summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-05-19 13:21:27 +0000
committerrandomdan <randomdan@localhost>2014-05-19 13:21:27 +0000
commit24fde0910fd3f9bb9ccd69f9090f2cbcb5f64f36 (patch)
tree44141c0e736fa7432919c5ac0bfd5d38d02bd2ac
parentUse IceUtil::Shared/Handle, which is already thread safe, instead of boost::i... (diff)
downloadnetfs-24fde0910fd3f9bb9ccd69f9090f2cbcb5f64f36.tar.bz2
netfs-24fde0910fd3f9bb9ccd69f9090f2cbcb5f64f36.tar.xz
netfs-24fde0910fd3f9bb9ccd69f9090f2cbcb5f64f36.zip
Centralise some better lock helpers
-rw-r--r--netfs/fuse/fuse.cpp5
-rw-r--r--netfs/fuse/fuse.h3
-rw-r--r--netfs/fuse/fuseDirs.cpp7
-rw-r--r--netfs/fuse/fuseFiles.cpp7
-rw-r--r--netfs/lib/entCache.cpp18
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 <string.h>
#include <boost/foreach.hpp>
#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<boost::shared_mutex> _lck(_lock)
-#define SLOCK boost::shared_lock<boost::shared_mutex> _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 <string.h>
#include <typeConvert.h>
#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 <exceptions.h>
-
-#define LOCK boost::unique_lock<boost::shared_mutex> _lck(lock)
-#define SLOCK boost::shared_lock<boost::shared_mutex> _lck(lock)
+#include "lockHelpers.h"
template<class id_t, class name_t>
EntCache<id_t, name_t>::EntCache()
@@ -19,15 +17,14 @@ template<class id_t, class name_t>
const id_t &
EntCache<id_t, name_t>::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<class id_t, class name_t>
const name_t &
EntCache<id_t, name_t>::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<uid_t, std::string>;
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()) {