*: use std::scoped_lock with implicit template parameter

This commit is contained in:
Max Kellermann
2024-05-23 20:43:31 +02:00
parent 4fc3230fe6
commit 381215fd73
68 changed files with 253 additions and 253 deletions

View File

@@ -179,7 +179,7 @@ CompositeStorage::~CompositeStorage() = default;
Storage *
CompositeStorage::GetMount(std::string_view uri) noexcept
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
auto result = FindStorage(uri);
if (!result.uri.empty())
@@ -192,7 +192,7 @@ CompositeStorage::GetMount(std::string_view uri) noexcept
void
CompositeStorage::Mount(const char *uri, std::unique_ptr<Storage> storage)
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
Directory &directory = root.Make(uri);
assert(!directory.storage);
@@ -202,7 +202,7 @@ CompositeStorage::Mount(const char *uri, std::unique_ptr<Storage> storage)
bool
CompositeStorage::Unmount(const char *uri)
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
return root.Unmount(uri);
}
@@ -231,7 +231,7 @@ CompositeStorage::FindStorage(std::string_view uri) const noexcept
StorageFileInfo
CompositeStorage::GetInfo(std::string_view uri, bool follow)
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
std::exception_ptr error;
@@ -257,7 +257,7 @@ CompositeStorage::GetInfo(std::string_view uri, bool follow)
std::unique_ptr<StorageDirectoryReader>
CompositeStorage::OpenDirectory(std::string_view uri)
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
auto f = FindStorage(uri);
const Directory *directory = f.directory->Find(f.uri);
@@ -284,7 +284,7 @@ CompositeStorage::OpenDirectory(std::string_view uri)
std::string
CompositeStorage::MapUTF8(std::string_view uri) const noexcept
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
auto f = FindStorage(uri);
if (f.directory->storage == nullptr)
@@ -296,7 +296,7 @@ CompositeStorage::MapUTF8(std::string_view uri) const noexcept
AllocatedPath
CompositeStorage::MapFS(std::string_view uri) const noexcept
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
auto f = FindStorage(uri);
if (f.directory->storage == nullptr)
@@ -308,7 +308,7 @@ CompositeStorage::MapFS(std::string_view uri) const noexcept
std::string_view
CompositeStorage::MapToRelativeUTF8(std::string_view uri) const noexcept
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
if (root.storage != nullptr) {
auto result = root.storage->MapToRelativeUTF8(uri);
@@ -325,7 +325,7 @@ CompositeStorage::MapToRelativeUTF8(std::string_view uri) const noexcept
InputStreamPtr
CompositeStorage::OpenFile(std::string_view uri_utf8, Mutex &_mutex)
{
const std::lock_guard<Mutex> lock(mutex);
const std::lock_guard lock{mutex};
auto f = FindStorage(uri_utf8);
if (f.directory->storage == nullptr)

View File

@@ -99,7 +99,7 @@ public:
*/
template<typename T>
void VisitMounts(T t) const {
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
std::string uri;
VisitMounts(uri, root, t);
}
@@ -109,7 +109,7 @@ public:
*/
[[gnu::pure]] [[gnu::nonnull]]
bool IsMounted(const char *storage_uri) const noexcept {
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
return IsMounted(root, storage_uri);
}

View File

@@ -109,7 +109,7 @@ public:
}
void Wait() {
std::unique_lock<Mutex> lock(mutex);
std::unique_lock lock{mutex};
cond.wait(lock, [this]{ return done; });
if (postponed_error)
@@ -130,7 +130,7 @@ protected:
}
void LockSetDone() {
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};
SetDone();
}
@@ -148,7 +148,7 @@ private:
/* virtual methods from CurlResponseHandler */
void OnError(std::exception_ptr e) noexcept final {
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};
postponed_error = std::move(e);
SetDone();
}

View File

@@ -140,7 +140,7 @@ private:
void SetState(State _state) noexcept {
assert(GetEventLoop().IsInside());
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
state = _state;
cond.notify_all();
}
@@ -148,7 +148,7 @@ private:
void SetState(State _state, std::exception_ptr &&e) noexcept {
assert(GetEventLoop().IsInside());
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
state = _state;
last_exception = std::move(e);
cond.notify_all();
@@ -172,7 +172,7 @@ private:
}
void WaitConnected() {
std::unique_lock<Mutex> lock(mutex);
std::unique_lock lock{mutex};
while (true) {
switch (state) {

View File

@@ -89,7 +89,7 @@ GetInfo(SmbclientContext &ctx, Mutex &mutex, const char *path)
struct stat st;
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
if (ctx.Stat(path, st) != 0)
throw MakeErrno("Failed to access file");
}
@@ -131,7 +131,7 @@ SmbclientStorage::OpenDirectory(std::string_view uri_utf8)
SMBCFILE *handle;
{
const std::scoped_lock<Mutex> protect(mutex);
const std::scoped_lock protect{mutex};
handle = ctx.OpenDirectory(mapped.c_str());
}
@@ -152,14 +152,14 @@ SkipNameFS(PathTraitsFS::const_pointer name) noexcept
SmbclientDirectoryReader::~SmbclientDirectoryReader()
{
const std::scoped_lock<Mutex> lock(storage.mutex);
const std::scoped_lock lock{storage.mutex};
storage.ctx.CloseDirectory(handle);
}
const char *
SmbclientDirectoryReader::Read() noexcept
{
const std::scoped_lock<Mutex> protect(storage.mutex);
const std::scoped_lock protect{storage.mutex};
while (auto e = storage.ctx.ReadDirectory(handle)) {
name = e->name;

View File

@@ -151,7 +151,7 @@ UdisksStorage::SetMountPoint(Path mount_point)
void
UdisksStorage::LockSetMountPoint(Path mount_point)
{
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};
SetMountPoint(mount_point);
}
@@ -183,7 +183,7 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept
return;
}
} catch (...) {
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};
mount_error = std::current_exception();
want_mount = false;
cond.notify_all();
@@ -196,7 +196,7 @@ UdisksStorage::OnListReply(ODBus::Message reply) noexcept
void
UdisksStorage::MountWait()
{
std::unique_lock<Mutex> lock(mutex);
std::unique_lock lock{mutex};
if (mounted_storage)
/* already mounted */
@@ -239,7 +239,7 @@ try {
mount_request.Send(connection, *msg.Get(),
[this](auto o) { return OnMountNotify(std::move(o)); });
} catch (...) {
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};
mount_error = std::current_exception();
want_mount = false;
cond.notify_all();
@@ -258,7 +258,7 @@ try {
const char *mount_path = i.GetString();
LockSetMountPoint(Path::FromFS(mount_path));
} catch (...) {
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};
mount_error = std::current_exception();
want_mount = false;
cond.notify_all();
@@ -267,7 +267,7 @@ try {
void
UdisksStorage::UnmountWait()
{
std::unique_lock<Mutex> lock(mutex);
std::unique_lock lock{mutex};
if (!mounted_storage)
/* not mounted */
@@ -296,7 +296,7 @@ try {
mount_request.Send(connection, *msg.Get(),
[this](auto u) { return OnUnmountNotify(std::move(u)); });
} catch (...) {
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};
mount_error = std::current_exception();
mounted_storage.reset();
cond.notify_all();
@@ -308,12 +308,12 @@ try {
using namespace ODBus;
reply.CheckThrowError();
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};
mount_error = {};
mounted_storage.reset();
cond.notify_all();
} catch (...) {
const std::scoped_lock<Mutex> lock(mutex);
const std::scoped_lock lock{mutex};
mount_error = std::current_exception();
mounted_storage.reset();
cond.notify_all();