From f82e1453e476bd6c9114e2adf4144eb643950b0e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 13 Nov 2017 17:12:21 +0100 Subject: [PATCH] input/smbclient: use std::lock_guard --- src/input/plugins/SmbclientInputPlugin.cxx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/input/plugins/SmbclientInputPlugin.cxx b/src/input/plugins/SmbclientInputPlugin.cxx index 8e802a8e1..35bb5c5b8 100644 --- a/src/input/plugins/SmbclientInputPlugin.cxx +++ b/src/input/plugins/SmbclientInputPlugin.cxx @@ -125,9 +125,13 @@ input_smbclient_open(const char *uri, size_t SmbclientInputStream::Read(void *ptr, size_t read_size) { - smbclient_mutex.lock(); - ssize_t nbytes = smbc_read(fd, ptr, read_size); - smbclient_mutex.unlock(); + ssize_t nbytes; + + { + const std::lock_guard lock(smbclient_mutex); + nbytes = smbc_read(fd, ptr, read_size); + } + if (nbytes < 0) throw MakeErrno("smbc_read() failed"); @@ -138,9 +142,13 @@ SmbclientInputStream::Read(void *ptr, size_t read_size) void SmbclientInputStream::Seek(offset_type new_offset) { - smbclient_mutex.lock(); - off_t result = smbc_lseek(fd, new_offset, SEEK_SET); - smbclient_mutex.unlock(); + off_t result; + + { + const std::lock_guard lock(smbclient_mutex); + result = smbc_lseek(fd, new_offset, SEEK_SET); + } + if (result < 0) throw MakeErrno("smbc_lseek() failed");