input/smbclient: use std::lock_guard

This commit is contained in:
Max Kellermann 2017-11-13 17:12:21 +01:00
parent a2b77c8813
commit f82e1453e4
1 changed files with 14 additions and 6 deletions

View File

@ -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<Mutex> 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<Mutex> lock(smbclient_mutex);
result = smbc_lseek(fd, new_offset, SEEK_SET);
}
if (result < 0)
throw MakeErrno("smbc_lseek() failed");