summaryrefslogtreecommitdiffstats
path: root/stream
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-07-11 22:16:06 +0200
committerwm4 <wm4@nowhere>2016-07-11 22:16:06 +0200
commitf4d62dc4a0ae52883a081f1d0f955fd83d51e59a (patch)
treec47da2dd5c94f7c0d7b68d5dfce5fc82f33df1c7 /stream
parent374600cec0590acad9cdba6b91f6b845921b5799 (diff)
downloadmpv-f4d62dc4a0ae52883a081f1d0f955fd83d51e59a.tar.bz2
mpv-f4d62dc4a0ae52883a081f1d0f955fd83d51e59a.tar.xz
cache: fix previous commit
The cache reader thread actually unlocks the mutex protecting the underlying stream while reading from it. That's why other code goes out of its way to run certain stream operations on the cache thread. Do the same. We could have this simpler by creating a mechanism that would "park" the cache thread and make it wait for the lock (while we have it) in order to gain exclusive access. This could be done in the future.
Diffstat (limited to 'stream')
-rw-r--r--stream/cache.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/stream/cache.c b/stream/cache.c
index 70a34f88df..02d618f18d 100644
--- a/stream/cache.c
+++ b/stream/cache.c
@@ -124,6 +124,7 @@ enum {
CACHE_CTRL_NONE = 0,
CACHE_CTRL_QUIT = -1,
CACHE_CTRL_PING = -2,
+ CACHE_CTRL_SEEK = -3,
// we should fill buffer only if space>=FILL_LIMIT
FILL_LIMIT = 16 * 1024,
@@ -505,6 +506,10 @@ static void *cache_thread(void *arg)
}
if (s->control > 0) {
cache_execute_control(s);
+ } else if (s->control == CACHE_CTRL_SEEK) {
+ s->control_res = cache_update_stream_position(s);
+ s->control = CACHE_CTRL_NONE;
+ pthread_cond_signal(&s->wakeup);
} else {
cache_fill(s);
}
@@ -579,7 +584,12 @@ static int cache_seek(stream_t *cache, int64_t pos)
} else {
cache->pos = s->read_filepos = s->read_min = pos;
s->eof = false; // so that cache_read() will actually wait for new data
- r = cache_update_stream_position(s);
+ 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);
+ r = s->control_res;
pthread_cond_signal(&s->wakeup);
}