mirror of
https://github.com/mpv-player/mpv
synced 2024-10-30 04:46:41 +01:00
cache: another minor simplification
The caller can check for cache interruption instead. There's no need to define special return values and such. It would be rather hard to make waiting for the condition and stream cancellation atomic too (and pointless, since the underlying stream will also be "cancelled" and exit early), so nothing about cancellation being a separate call will change.
This commit is contained in:
parent
3990fe74f6
commit
1299fbec05
@ -114,8 +114,6 @@ struct priv {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
CACHE_INTERRUPTED = -1,
|
|
||||||
|
|
||||||
CACHE_CTRL_NONE = 0,
|
CACHE_CTRL_NONE = 0,
|
||||||
CACHE_CTRL_QUIT = -1,
|
CACHE_CTRL_QUIT = -1,
|
||||||
CACHE_CTRL_PING = -2,
|
CACHE_CTRL_PING = -2,
|
||||||
@ -127,12 +125,8 @@ enum {
|
|||||||
// Used by the main thread to wakeup the cache thread, and to wait for the
|
// Used by the main thread to wakeup the cache thread, and to wait for the
|
||||||
// cache thread. The cache mutex has to be locked when calling this function.
|
// cache thread. The cache mutex has to be locked when calling this function.
|
||||||
// *retry_time should be set to 0 on the first call.
|
// *retry_time should be set to 0 on the first call.
|
||||||
// Returns CACHE_INTERRUPTED if the caller is supposed to abort.
|
static void cache_wakeup_and_wait(struct priv *s, double *retry_time)
|
||||||
static int cache_wakeup_and_wait(struct priv *s, double *retry_time)
|
|
||||||
{
|
{
|
||||||
if (mp_cancel_test(s->cache->cancel))
|
|
||||||
return CACHE_INTERRUPTED;
|
|
||||||
|
|
||||||
double start = mp_time_sec();
|
double start = mp_time_sec();
|
||||||
if (*retry_time >= CACHE_WAIT_TIME) {
|
if (*retry_time >= CACHE_WAIT_TIME) {
|
||||||
MP_WARN(s, "Cache is not responding - slow/stuck network connection?\n");
|
MP_WARN(s, "Cache is not responding - slow/stuck network connection?\n");
|
||||||
@ -144,8 +138,6 @@ static int cache_wakeup_and_wait(struct priv *s, double *retry_time)
|
|||||||
|
|
||||||
if (*retry_time >= 0)
|
if (*retry_time >= 0)
|
||||||
*retry_time += mp_time_sec() - start;
|
*retry_time += mp_time_sec() - start;
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runs in the cache thread
|
// Runs in the cache thread
|
||||||
@ -501,8 +493,9 @@ static int cache_fill_buffer(struct stream *cache, char *buffer, int max_len)
|
|||||||
if (s->eof && s->read_filepos >= s->max_filepos && s->reads >= retry)
|
if (s->eof && s->read_filepos >= s->max_filepos && s->reads >= retry)
|
||||||
break;
|
break;
|
||||||
s->idle = false;
|
s->idle = false;
|
||||||
if (cache_wakeup_and_wait(s, &retry_time) == CACHE_INTERRUPTED)
|
if (mp_cancel_test(s->cache->cancel))
|
||||||
break;
|
break;
|
||||||
|
cache_wakeup_and_wait(s, &retry_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,11 +553,12 @@ static int cache_control(stream_t *cache, int cmd, void *arg)
|
|||||||
s->control_arg = arg;
|
s->control_arg = arg;
|
||||||
double retry = 0;
|
double retry = 0;
|
||||||
while (s->control != CACHE_CTRL_NONE) {
|
while (s->control != CACHE_CTRL_NONE) {
|
||||||
if (cache_wakeup_and_wait(s, &retry) == CACHE_INTERRUPTED) {
|
if (mp_cancel_test(s->cache->cancel)) {
|
||||||
s->eof = 1;
|
s->eof = 1;
|
||||||
r = STREAM_UNSUPPORTED;
|
r = STREAM_UNSUPPORTED;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
cache_wakeup_and_wait(s, &retry);
|
||||||
}
|
}
|
||||||
r = s->control_res;
|
r = s->control_res;
|
||||||
if (s->control_flush) {
|
if (s->control_flush) {
|
||||||
|
Loading…
Reference in New Issue
Block a user