From 24fde0910fd3f9bb9ccd69f9090f2cbcb5f64f36 Mon Sep 17 00:00:00 2001 From: randomdan Date: Mon, 19 May 2014 13:21:27 +0000 Subject: Centralise some better lock helpers --- netfs/fuse/fuse.cpp | 5 +++-- netfs/fuse/fuse.h | 3 --- netfs/fuse/fuseDirs.cpp | 7 ++++--- netfs/fuse/fuseFiles.cpp | 7 ++++--- netfs/lib/entCache.cpp | 18 +++++++----------- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/netfs/fuse/fuse.cpp b/netfs/fuse/fuse.cpp index aac2f78..d9d49fc 100644 --- a/netfs/fuse/fuse.cpp +++ b/netfs/fuse/fuse.cpp @@ -2,6 +2,7 @@ #include #include #include "fuse.h" +#include "lockHelpers.h" NetFS::FuseApp::FuseApp(int & argc, char ** argv) : _argc(argc), @@ -59,7 +60,7 @@ void NetFS::FuseApp::connectToService() { if (!service) { - LOCK; + Lock(_lock); FuseConfig::ExportPtr e = fc->exports[exportName]; const std::string & ep = *e->endpoints.begin(); @@ -105,7 +106,7 @@ NetFS::FuseApp::connectHandles() void NetFS::FuseApp::verifyConnection() { - LOCK; + Lock(_lock); if (service) { try { service->ice_ping(); diff --git a/netfs/fuse/fuse.h b/netfs/fuse/fuse.h index 0b9e10e..a271630 100644 --- a/netfs/fuse/fuse.h +++ b/netfs/fuse/fuse.h @@ -8,9 +8,6 @@ #include "fuseConfig.h" #include "entCache.h" -#define LOCK boost::unique_lock _lck(_lock) -#define SLOCK boost::shared_lock _lck(_lock) - namespace NetFS { class FuseApp : public FuseAppBase { private: diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp index fac70a6..e09b68b 100644 --- a/netfs/fuse/fuseDirs.cpp +++ b/netfs/fuse/fuseDirs.cpp @@ -1,6 +1,7 @@ #include "pch.hpp" #include "fuse.h" #include "misc.h" +#include "lockHelpers.h" NetFS::FuseApp::OpenDir::OpenDir(DirectoryPrx r, const std::string & p) : remote(r), @@ -11,7 +12,7 @@ NetFS::FuseApp::OpenDir::OpenDir(DirectoryPrx r, const std::string & p) : void NetFS::FuseApp::setProxy(OpenDirPtr od, uint64_t & fh) { - LOCK; + Lock(_lock); while (openDirs.find(fh = ++openDirID) != openDirs.end()) ; openDirs.insert({ fh, od }); } @@ -19,7 +20,7 @@ NetFS::FuseApp::setProxy(OpenDirPtr od, uint64_t & fh) NetFS::FuseApp::OpenDirPtr NetFS::FuseApp::getDirProxy(uint64_t localID) const { - SLOCK; + SharedLock(_lock); OpenDirs::const_iterator i = openDirs.find(localID); if (i != openDirs.end()) { return i->second; @@ -30,7 +31,7 @@ NetFS::FuseApp::getDirProxy(uint64_t localID) const void NetFS::FuseApp::clearDirProxy(uint64_t localID) { - LOCK; + Lock(_lock); openDirs.erase(localID); } diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index 4a96e51..112c383 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -2,6 +2,7 @@ #include #include #include "fuse.h" +#include "lockHelpers.h" NetFS::FuseApp::OpenFile::OpenFile(FilePrx r, const std::string & p, int f) : remote(r), @@ -13,7 +14,7 @@ NetFS::FuseApp::OpenFile::OpenFile(FilePrx r, const std::string & p, int f) : void NetFS::FuseApp::setProxy(OpenFilePtr of, uint64_t & fh) { - LOCK; + Lock(_lock); while (openFiles.find(fh = ++openFileID) != openFiles.end()) ; openFiles.insert({ fh, of }); } @@ -21,7 +22,7 @@ NetFS::FuseApp::setProxy(OpenFilePtr of, uint64_t & fh) NetFS::FuseApp::OpenFilePtr NetFS::FuseApp::getFileProxy(uint64_t localID) const { - SLOCK; + SharedLock(_lock); OpenFiles::const_iterator i = openFiles.find(localID); if (i != openFiles.end()) { return i->second; @@ -32,7 +33,7 @@ NetFS::FuseApp::getFileProxy(uint64_t localID) const void NetFS::FuseApp::clearFileProxy(uint64_t localID) { - LOCK; + Lock(_lock); openFiles.erase(localID); } diff --git a/netfs/lib/entCache.cpp b/netfs/lib/entCache.cpp index 7dee1e6..02735b4 100644 --- a/netfs/lib/entCache.cpp +++ b/netfs/lib/entCache.cpp @@ -1,9 +1,7 @@ #include "pch.hpp" #include "entCache.h" #include - -#define LOCK boost::unique_lock _lck(lock) -#define SLOCK boost::shared_lock _lck(lock) +#include "lockHelpers.h" template EntCache::EntCache() @@ -19,15 +17,14 @@ template const id_t & EntCache::getID(const name_t & u) const { - { - SLOCK; + SharedScopeLock(lock) { typename IDs::right_map::const_iterator cu = idcache.right.find(u); if (cu != idcache.right.end()) { return cu->second; } } fillCache(); - SLOCK; + SharedLock(lock); typename IDs::right_map::const_iterator cu = idcache.right.find(u); if (cu != idcache.right.end()) { return cu->second; @@ -39,15 +36,14 @@ template const name_t & EntCache::getName(const id_t & u) const { - { - SLOCK; + SharedScopeLock(lock) { typename IDs::left_map::const_iterator cu = idcache.left.find(u); if (cu != idcache.left.end()) { return cu->second; } } fillCache(); - SLOCK; + SharedLock(lock); typename IDs::left_map::const_iterator cu = idcache.left.find(u); if (cu != idcache.left.end()) { return cu->second; @@ -59,7 +55,7 @@ template class EntCache; void UserEntCache::fillCache() const { - LOCK; + Lock(lock); setpwent(); idcache.clear(); while (struct passwd * pwp = getpwent()) { @@ -71,7 +67,7 @@ UserEntCache::fillCache() const void GroupEntCache::fillCache() const { - LOCK; + Lock(lock); setgrent(); idcache.clear(); while (struct group * grpp = getgrent()) { -- cgit v1.2.3