From 6d5135aa23f2ae12d953ceab1c1d01e003a55be1 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 25 Aug 2015 21:47:49 +0000 Subject: Added more lock/unlock features to the cache Lockers. That...was a weird sentence, but it's true. Also, oddly enough, Lockers aren't thread-safe, but they shouldn't ever have to be. Figure that one out! --- src/unstable/cachebase.h | 8 ++++++++ src/unstable/cacheobject.h | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src/unstable') diff --git a/src/unstable/cachebase.h b/src/unstable/cachebase.h index d5b4382..2e0f24f 100644 --- a/src/unstable/cachebase.h +++ b/src/unstable/cachebase.h @@ -351,6 +351,14 @@ namespace Bu bLocked = false; } + void lock() + { + if( bLocked ) + return; + rPtr.lock(); + bLocked = true; + } + private: MyType &rPtr; bool bLocked; diff --git a/src/unstable/cacheobject.h b/src/unstable/cacheobject.h index e519a9c..080312f 100644 --- a/src/unstable/cacheobject.h +++ b/src/unstable/cacheobject.h @@ -69,18 +69,36 @@ namespace Bu { public: Locker( const MyType *pObj ) : - pObj( pObj ) + pObj( pObj ), + bLocked( true ) { pObj->lock(); } ~Locker() { + unlock(); + } + + void unlock() + { + if( !bLocked ) + return; pObj->unlock(); + bLocked = false; + } + + void lock() + { + if( bLocked ) + return; + pObj->lock(); + bLocked = true; } private: const MyType *pObj; + bool bLocked; }; protected: -- cgit v1.2.3