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.
This commit is contained in:
Max Kellermann 2014-10-01 22:15:06 +02:00
parent 0470f648c6
commit 10cc87e422
2 changed files with 12 additions and 18 deletions

View File

@ -135,10 +135,9 @@ NfsConnection::~NfsConnection()
void void
NfsConnection::AddLease(NfsLease &lease) NfsConnection::AddLease(NfsLease &lease)
{ {
{ assert(GetEventLoop().IsInside());
const ScopeLock protect(mutex);
new_leases.push_back(&lease); new_leases.push_back(&lease);
}
DeferredMonitor::Schedule(); DeferredMonitor::Schedule();
} }
@ -146,7 +145,7 @@ NfsConnection::AddLease(NfsLease &lease)
void void
NfsConnection::RemoveLease(NfsLease &lease) NfsConnection::RemoveLease(NfsLease &lease)
{ {
const ScopeLock protect(mutex); assert(GetEventLoop().IsInside());
new_leases.remove(&lease); new_leases.remove(&lease);
active_leases.remove(&lease); active_leases.remove(&lease);
@ -220,6 +219,7 @@ NfsConnection::Close(struct nfsfh *fh)
void void
NfsConnection::DestroyContext() NfsConnection::DestroyContext()
{ {
assert(GetEventLoop().IsInside());
assert(context != nullptr); assert(context != nullptr);
if (SocketMonitor::IsDefined()) if (SocketMonitor::IsDefined())
@ -271,8 +271,6 @@ NfsConnection::OnSocketReady(unsigned flags)
in_service = false; in_service = false;
if (!was_mounted && mount_finished) { if (!was_mounted && mount_finished) {
const ScopeLock protect(mutex);
if (postponed_mount_error.IsDefined()) { if (postponed_mount_error.IsDefined()) {
DestroyContext(); DestroyContext();
closed = true; closed = true;
@ -285,8 +283,6 @@ NfsConnection::OnSocketReady(unsigned flags)
error.Format(nfs_domain, "NFS connection has failed: %s", error.Format(nfs_domain, "NFS connection has failed: %s",
nfs_get_error(context)); nfs_get_error(context));
const ScopeLock protect(mutex);
DestroyContext(); DestroyContext();
closed = true; closed = true;
@ -303,8 +299,6 @@ NfsConnection::OnSocketReady(unsigned flags)
error.Format(nfs_domain, error.Format(nfs_domain,
"NFS socket disappeared: %s", msg); "NFS socket disappeared: %s", msg);
const ScopeLock protect(mutex);
DestroyContext(); DestroyContext();
closed = true; closed = true;
@ -379,6 +373,8 @@ NfsConnection::MountInternal(Error &error)
void void
NfsConnection::BroadcastMountSuccess() NfsConnection::BroadcastMountSuccess()
{ {
assert(GetEventLoop().IsInside());
while (!new_leases.empty()) { while (!new_leases.empty()) {
auto i = new_leases.begin(); auto i = new_leases.begin();
active_leases.splice(active_leases.end(), new_leases, i); active_leases.splice(active_leases.end(), new_leases, i);
@ -389,6 +385,8 @@ NfsConnection::BroadcastMountSuccess()
void void
NfsConnection::BroadcastMountError(Error &&error) NfsConnection::BroadcastMountError(Error &&error)
{ {
assert(GetEventLoop().IsInside());
while (!new_leases.empty()) { while (!new_leases.empty()) {
auto l = new_leases.front(); auto l = new_leases.front();
new_leases.pop_front(); new_leases.pop_front();
@ -401,6 +399,8 @@ NfsConnection::BroadcastMountError(Error &&error)
void void
NfsConnection::BroadcastError(Error &&error) NfsConnection::BroadcastError(Error &&error)
{ {
assert(GetEventLoop().IsInside());
while (!active_leases.empty()) { while (!active_leases.empty()) {
auto l = active_leases.front(); auto l = active_leases.front();
active_leases.pop_front(); active_leases.pop_front();
@ -416,14 +416,11 @@ NfsConnection::RunDeferred()
{ {
Error error; Error error;
if (!MountInternal(error)) { if (!MountInternal(error)) {
const ScopeLock protect(mutex);
BroadcastMountError(std::move(error)); BroadcastMountError(std::move(error));
return; return;
} }
} }
if (mount_finished) { if (mount_finished)
const ScopeLock protect(mutex);
BroadcastMountSuccess(); BroadcastMountSuccess();
}
} }

View File

@ -22,7 +22,6 @@
#include "Lease.hxx" #include "Lease.hxx"
#include "Cancellable.hxx" #include "Cancellable.hxx"
#include "thread/Mutex.hxx"
#include "event/SocketMonitor.hxx" #include "event/SocketMonitor.hxx"
#include "event/DeferredMonitor.hxx" #include "event/DeferredMonitor.hxx"
#include "util/Error.hxx" #include "util/Error.hxx"
@ -64,8 +63,6 @@ class NfsConnection : SocketMonitor, DeferredMonitor {
nfs_context *context; nfs_context *context;
Mutex mutex;
typedef std::list<NfsLease *> LeaseList; typedef std::list<NfsLease *> LeaseList;
LeaseList new_leases, active_leases; LeaseList new_leases, active_leases;