input/{cdio,ffmpeg,file,smbclient}: unlock the mutex during blocking I/O
InputStream::Read() and InputStream::Seek() are called with the mutex locked. That means the implementation must not block, or unlock the mutex before calling into blocking code. Previously, a slow CD drive could stall the whole MPD process, including the main thread, due to this problem. Closes #149
This commit is contained in:
parent
f82e1453e4
commit
31ab78ae8e
2
NEWS
2
NEWS
|
@ -1,5 +1,7 @@
|
||||||
ver 0.20.12 (not yet released)
|
ver 0.20.12 (not yet released)
|
||||||
* input
|
* input
|
||||||
|
- cdio_paranoia, ffmpeg, file, smbclient: reduce lock contention,
|
||||||
|
fixing lots of xrun problems
|
||||||
- curl: fix seeking
|
- curl: fix seeking
|
||||||
* decoder
|
* decoder
|
||||||
- ffmpeg: fix GCC 8 warning
|
- ffmpeg: fix GCC 8 warning
|
||||||
|
|
|
@ -270,8 +270,11 @@ CdioParanoiaInputStream::Seek(offset_type new_offset)
|
||||||
lsn_relofs = new_offset / CDIO_CD_FRAMESIZE_RAW;
|
lsn_relofs = new_offset / CDIO_CD_FRAMESIZE_RAW;
|
||||||
offset = new_offset;
|
offset = new_offset;
|
||||||
|
|
||||||
|
{
|
||||||
|
const ScopeUnlock unlock(mutex);
|
||||||
cdio_paranoia_seek(para, lsn_from + lsn_relofs, SEEK_SET);
|
cdio_paranoia_seek(para, lsn_from + lsn_relofs, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
CdioParanoiaInputStream::Read(void *ptr, size_t length)
|
CdioParanoiaInputStream::Read(void *ptr, size_t length)
|
||||||
|
@ -292,6 +295,8 @@ CdioParanoiaInputStream::Read(void *ptr, size_t length)
|
||||||
|
|
||||||
//current sector was changed ?
|
//current sector was changed ?
|
||||||
if (lsn_relofs != buffer_lsn) {
|
if (lsn_relofs != buffer_lsn) {
|
||||||
|
const ScopeUnlock unlock(mutex);
|
||||||
|
|
||||||
rbuf = cdio_paranoia_read(para, nullptr);
|
rbuf = cdio_paranoia_read(para, nullptr);
|
||||||
|
|
||||||
s_err = cdda_errors(drv);
|
s_err = cdda_errors(drv);
|
||||||
|
|
|
@ -104,7 +104,13 @@ input_ffmpeg_open(const char *uri,
|
||||||
size_t
|
size_t
|
||||||
FfmpegInputStream::Read(void *ptr, size_t read_size)
|
FfmpegInputStream::Read(void *ptr, size_t read_size)
|
||||||
{
|
{
|
||||||
auto result = avio_read(h, (unsigned char *)ptr, read_size);
|
int result;
|
||||||
|
|
||||||
|
{
|
||||||
|
const ScopeUnlock unlock(mutex);
|
||||||
|
result = avio_read(h, (unsigned char *)ptr, read_size);
|
||||||
|
}
|
||||||
|
|
||||||
if (result <= 0) {
|
if (result <= 0) {
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
throw MakeFfmpegError(result, "avio_read() failed");
|
throw MakeFfmpegError(result, "avio_read() failed");
|
||||||
|
@ -126,7 +132,12 @@ FfmpegInputStream::IsEOF() noexcept
|
||||||
void
|
void
|
||||||
FfmpegInputStream::Seek(offset_type new_offset)
|
FfmpegInputStream::Seek(offset_type new_offset)
|
||||||
{
|
{
|
||||||
auto result = avio_seek(h, new_offset, SEEK_SET);
|
int64_t result;
|
||||||
|
|
||||||
|
{
|
||||||
|
const ScopeUnlock unlock(mutex);
|
||||||
|
result = avio_seek(h, new_offset, SEEK_SET);
|
||||||
|
}
|
||||||
|
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
throw MakeFfmpegError(result, "avio_seek() failed");
|
throw MakeFfmpegError(result, "avio_seek() failed");
|
||||||
|
|
|
@ -87,14 +87,24 @@ input_file_open(gcc_unused const char *filename,
|
||||||
void
|
void
|
||||||
FileInputStream::Seek(offset_type new_offset)
|
FileInputStream::Seek(offset_type new_offset)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
const ScopeUnlock unlock(mutex);
|
||||||
reader.Seek((off_t)new_offset);
|
reader.Seek((off_t)new_offset);
|
||||||
|
}
|
||||||
|
|
||||||
offset = new_offset;
|
offset = new_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
FileInputStream::Read(void *ptr, size_t read_size)
|
FileInputStream::Read(void *ptr, size_t read_size)
|
||||||
{
|
{
|
||||||
size_t nbytes = reader.Read(ptr, read_size);
|
size_t nbytes;
|
||||||
|
|
||||||
|
{
|
||||||
|
const ScopeUnlock unlock(mutex);
|
||||||
|
nbytes = reader.Read(ptr, read_size);
|
||||||
|
}
|
||||||
|
|
||||||
offset += nbytes;
|
offset += nbytes;
|
||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,7 @@ SmbclientInputStream::Read(void *ptr, size_t read_size)
|
||||||
ssize_t nbytes;
|
ssize_t nbytes;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
const ScopeUnlock unlock(mutex);
|
||||||
const std::lock_guard<Mutex> lock(smbclient_mutex);
|
const std::lock_guard<Mutex> lock(smbclient_mutex);
|
||||||
nbytes = smbc_read(fd, ptr, read_size);
|
nbytes = smbc_read(fd, ptr, read_size);
|
||||||
}
|
}
|
||||||
|
@ -145,6 +146,7 @@ SmbclientInputStream::Seek(offset_type new_offset)
|
||||||
off_t result;
|
off_t result;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
const ScopeUnlock unlock(mutex);
|
||||||
const std::lock_guard<Mutex> lock(smbclient_mutex);
|
const std::lock_guard<Mutex> lock(smbclient_mutex);
|
||||||
result = smbc_lseek(fd, new_offset, SEEK_SET);
|
result = smbc_lseek(fd, new_offset, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue