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
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();
}
}

View File

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