From 10cc87e422e09f437f86f56074dc2e018ed75bf1 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 1 Oct 2014 22:15:06 +0200 Subject: lib/nfs/Connection: remove Mutex All locks are currenly held from only a single thread (the IOThread) and thus we don't need the Mutex. --- src/lib/nfs/Connection.cxx | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'src/lib/nfs/Connection.cxx') diff --git a/src/lib/nfs/Connection.cxx b/src/lib/nfs/Connection.cxx index c07598189..89ef24312 100644 --- a/src/lib/nfs/Connection.cxx +++ b/src/lib/nfs/Connection.cxx @@ -135,10 +135,9 @@ NfsConnection::~NfsConnection() void NfsConnection::AddLease(NfsLease &lease) { - { - const ScopeLock protect(mutex); - new_leases.push_back(&lease); - } + assert(GetEventLoop().IsInside()); + + new_leases.push_back(&lease); DeferredMonitor::Schedule(); } @@ -146,7 +145,7 @@ NfsConnection::AddLease(NfsLease &lease) void NfsConnection::RemoveLease(NfsLease &lease) { - const ScopeLock protect(mutex); + assert(GetEventLoop().IsInside()); new_leases.remove(&lease); active_leases.remove(&lease); @@ -220,6 +219,7 @@ NfsConnection::Close(struct nfsfh *fh) void NfsConnection::DestroyContext() { + assert(GetEventLoop().IsInside()); assert(context != nullptr); if (SocketMonitor::IsDefined()) @@ -271,8 +271,6 @@ NfsConnection::OnSocketReady(unsigned flags) in_service = false; if (!was_mounted && mount_finished) { - const ScopeLock protect(mutex); - if (postponed_mount_error.IsDefined()) { DestroyContext(); closed = true; @@ -285,8 +283,6 @@ NfsConnection::OnSocketReady(unsigned flags) error.Format(nfs_domain, "NFS connection has failed: %s", nfs_get_error(context)); - const ScopeLock protect(mutex); - DestroyContext(); closed = true; @@ -303,8 +299,6 @@ NfsConnection::OnSocketReady(unsigned flags) error.Format(nfs_domain, "NFS socket disappeared: %s", msg); - const ScopeLock protect(mutex); - DestroyContext(); closed = true; @@ -379,6 +373,8 @@ NfsConnection::MountInternal(Error &error) void NfsConnection::BroadcastMountSuccess() { + assert(GetEventLoop().IsInside()); + while (!new_leases.empty()) { auto i = new_leases.begin(); active_leases.splice(active_leases.end(), new_leases, i); @@ -389,6 +385,8 @@ NfsConnection::BroadcastMountSuccess() void NfsConnection::BroadcastMountError(Error &&error) { + assert(GetEventLoop().IsInside()); + while (!new_leases.empty()) { auto l = new_leases.front(); new_leases.pop_front(); @@ -401,6 +399,8 @@ NfsConnection::BroadcastMountError(Error &&error) void NfsConnection::BroadcastError(Error &&error) { + assert(GetEventLoop().IsInside()); + while (!active_leases.empty()) { auto l = active_leases.front(); active_leases.pop_front(); @@ -416,14 +416,11 @@ NfsConnection::RunDeferred() { Error error; if (!MountInternal(error)) { - const ScopeLock protect(mutex); BroadcastMountError(std::move(error)); return; } } - if (mount_finished) { - const ScopeLock protect(mutex); + if (mount_finished) BroadcastMountSuccess(); - } } -- cgit v1.2.3