mirror of https://github.com/mpv-player/mpv
cache: minor simplification
Every cache_wakeup_and_wait() caller has to deal with asynchronous stream abort, so why not make it somehow part of the function.
This commit is contained in:
parent
f4d62dc4a0
commit
2d44dfaba9
|
@ -133,7 +133,8 @@ enum {
|
|||
// 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.
|
||||
// *retry_time should be set to 0 on the first call.
|
||||
static void cache_wakeup_and_wait(struct priv *s, double *retry_time)
|
||||
// Return false if the stream has been aborted.
|
||||
static bool cache_wakeup_and_wait(struct priv *s, double *retry_time)
|
||||
{
|
||||
double start = mp_time_sec();
|
||||
if (*retry_time >= CACHE_WAIT_TIME) {
|
||||
|
@ -147,6 +148,8 @@ static void cache_wakeup_and_wait(struct priv *s, double *retry_time)
|
|||
|
||||
if (*retry_time >= 0)
|
||||
*retry_time += mp_time_sec() - start;
|
||||
|
||||
return !mp_cancel_test(s->cache->cancel);
|
||||
}
|
||||
|
||||
// Runs in the cache thread
|
||||
|
@ -551,9 +554,8 @@ 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)
|
||||
break;
|
||||
s->idle = false;
|
||||
if (mp_cancel_test(s->cache->cancel))
|
||||
if (!cache_wakeup_and_wait(s, &retry_time))
|
||||
break;
|
||||
cache_wakeup_and_wait(s, &retry_time);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -587,8 +589,10 @@ static int cache_seek(stream_t *cache, int64_t pos)
|
|||
s->control = CACHE_CTRL_SEEK;
|
||||
s->control_res = 0;
|
||||
double retry = 0;
|
||||
while (s->control != CACHE_CTRL_NONE && !mp_cancel_test(s->cache->cancel))
|
||||
cache_wakeup_and_wait(s, &retry);
|
||||
while (s->control != CACHE_CTRL_NONE) {
|
||||
if (!cache_wakeup_and_wait(s, &retry))
|
||||
break;
|
||||
}
|
||||
r = s->control_res;
|
||||
pthread_cond_signal(&s->wakeup);
|
||||
}
|
||||
|
@ -617,12 +621,11 @@ static int cache_control(stream_t *cache, int cmd, void *arg)
|
|||
s->control_arg = arg;
|
||||
double retry = 0;
|
||||
while (s->control != CACHE_CTRL_NONE) {
|
||||
if (mp_cancel_test(s->cache->cancel)) {
|
||||
if (!cache_wakeup_and_wait(s, &retry)) {
|
||||
s->eof = 1;
|
||||
r = STREAM_UNSUPPORTED;
|
||||
goto done;
|
||||
}
|
||||
cache_wakeup_and_wait(s, &retry);
|
||||
}
|
||||
r = s->control_res;
|
||||
if (s->control_flush) {
|
||||
|
|
Loading…
Reference in New Issue