diff options
author | Max Kellermann <max@duempel.org> | 2011-09-14 21:46:41 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2011-09-16 21:22:13 +0200 |
commit | 754f26a97c816781e80500d98f2515ae97836145 (patch) | |
tree | caa7dbaa879b29d018a4559524390670ad33a605 /src/decoder_api.c | |
parent | 29241c4f835797f635816a9f37528aa981f722b5 (diff) | |
download | mpd-754f26a97c816781e80500d98f2515ae97836145.tar.gz mpd-754f26a97c816781e80500d98f2515ae97836145.tar.xz mpd-754f26a97c816781e80500d98f2515ae97836145.zip |
input_stream: non-blocking I/O
Add GMutex, GCond attributes which will be used by callers to
conditionally wait on the stream.
Remove the (now-useless) plugin method buffer(), wait on GCond
instead. Lock the input_stream before each method call. Do the same
with the playlist plugins.
Diffstat (limited to '')
-rw-r--r-- | src/decoder_api.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/decoder_api.c b/src/decoder_api.c index 20e976e69..1f2075638 100644 --- a/src/decoder_api.c +++ b/src/decoder_api.c @@ -183,8 +183,19 @@ size_t decoder_read(struct decoder *decoder, if (length == 0) return 0; - if (decoder_check_cancel_read(decoder)) - return 0; + input_stream_lock(is); + + while (true) { + if (decoder_check_cancel_read(decoder)) { + input_stream_unlock(is); + return 0; + } + + if (input_stream_available(is)) + break; + + g_cond_wait(is->cond, is->mutex); + } nbytes = input_stream_read(is, buffer, length, &error); assert(nbytes == 0 || error == NULL); @@ -195,6 +206,8 @@ size_t decoder_read(struct decoder *decoder, g_error_free(error); } + input_stream_unlock(is); + return nbytes; } @@ -241,7 +254,7 @@ update_stream_tag(struct decoder *decoder, struct input_stream *is) struct tag *tag; tag = is != NULL - ? input_stream_tag(is) + ? input_stream_lock_tag(is) : NULL; if (tag == NULL) { tag = decoder->song_tag; |