summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-04-21 22:34:32 +0200
committerwm4 <wm4@nowhere>2015-04-21 22:34:32 +0200
commit1299fbec05f80ab38b2335af1a6eea472eec62a8 (patch)
tree9b85325d5fd5b12072790b3e347fcddee585514a
parent3990fe74f6597ee6f8950a5640378f703f596a7a (diff)
downloadmpv-1299fbec05f80ab38b2335af1a6eea472eec62a8.tar.bz2
mpv-1299fbec05f80ab38b2335af1a6eea472eec62a8.tar.xz
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.
-rw-r--r--stream/cache.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/stream/cache.c b/stream/cache.c
index 9aab8285c3..b7ed76c8fa 100644
--- a/stream/cache.c
+++ b/stream/cache.c
@@ -114,8 +114,6 @@ struct priv {
};
enum {
- CACHE_INTERRUPTED = -1,
-
CACHE_CTRL_NONE = 0,
CACHE_CTRL_QUIT = -1,
CACHE_CTRL_PING = -2,
@@ -127,12 +125,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.
-// Returns CACHE_INTERRUPTED if the caller is supposed to abort.
-static int cache_wakeup_and_wait(struct priv *s, double *retry_time)
+static void 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();
if (*retry_time >= CACHE_WAIT_TIME) {
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)
*retry_time += mp_time_sec() - start;
-
- return 0;
}
// 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)
break;
s->idle = false;
- if (cache_wakeup_and_wait(s, &retry_time) == CACHE_INTERRUPTED)
+ if (mp_cancel_test(s->cache->cancel))
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;
double retry = 0;
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;
r = STREAM_UNSUPPORTED;
goto done;
}
+ cache_wakeup_and_wait(s, &retry);
}
r = s->control_res;
if (s->control_flush) {