summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-07-11 22:20:23 +0200
committerwm4 <wm4@nowhere>2016-07-11 22:20:23 +0200
commit2d44dfaba9d5fe47c35ab6b5d552a25f02bd0bd5 (patch)
treecd4b8e2ad840e32194e4105fe63e2e6b956227a8 /stream
parentf4d62dc4a0ae52883a081f1d0f955fd83d51e59a (diff)
downloadmpv-2d44dfaba9d5fe47c35ab6b5d552a25f02bd0bd5.tar.bz2
mpv-2d44dfaba9d5fe47c35ab6b5d552a25f02bd0bd5.tar.xz
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.
Diffstat (limited to 'stream')
-rw-r--r--stream/cache.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/stream/cache.c b/stream/cache.c
index 02d618f18d..3aad35d95d 100644
--- a/stream/cache.c
+++ b/stream/cache.c
@@ -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) {