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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user