From e97cac3fbab4a00faeb3ddec08846307670b9a0e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 20 Jul 2013 15:17:39 +0000 Subject: Added a Locker class to the Bu::CacheObject base class. This is a super simple wrapper that lets you take advantage of nifty Locker based mutex locking when in a CacheObject subclass. --- src/unstable/cacheobject.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/unstable/cacheobject.h b/src/unstable/cacheobject.h index 4606493..e83f706 100644 --- a/src/unstable/cacheobject.h +++ b/src/unstable/cacheobject.h @@ -33,6 +33,7 @@ namespace Bu { } + typedef CacheObject MyType; typedef CacheBase CacheType; virtual keytype getKey() const=0; @@ -62,6 +63,24 @@ namespace Bu return bChanged; } + class Locker + { + public: + Locker( const MyType *pObj ) : + pObj( pObj ) + { + pObj->lock(); + } + + ~Locker() + { + pObj->unlock(); + } + + private: + const MyType *pObj; + }; + protected: void changed( bool bChanged=true ) { -- cgit v1.2.3