summaryrefslogtreecommitdiff
path: root/src/unstable/cacheobject.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2013-04-08 12:10:31 +0000
committerMike Buland <eichlan@xagasoft.com>2013-04-08 12:10:31 +0000
commit7b1f2da0d83d4e01a8d8a32e02bea6b33c61e3f4 (patch)
tree4e6d4fa3814c58f8ce0f0f4e001b74972935adc4 /src/unstable/cacheobject.h
parentcc81b205410c2cf8e20a53eea745d9d8aee57f6c (diff)
downloadlibbu++-7b1f2da0d83d4e01a8d8a32e02bea6b33c61e3f4.tar.gz
libbu++-7b1f2da0d83d4e01a8d8a32e02bea6b33c61e3f4.tar.bz2
libbu++-7b1f2da0d83d4e01a8d8a32e02bea6b33c61e3f4.tar.xz
libbu++-7b1f2da0d83d4e01a8d8a32e02bea6b33c61e3f4.zip
Minor tweaks to the cache object base class. The per-object mutex is actually
in the CacheEntry class, not the CacheObject, so you can't lock it until you have an entry. This isn't a big deal unless your objects aren't actually part of a cache yet. I changed it so that lock/unlock have no effect if you haven't joined to a cache yet, probably not ideal, I'll think about moving that mutex. I also fixed it so you can lock/unlock even when const.
Diffstat (limited to '')
-rw-r--r--src/unstable/cacheobject.h15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/unstable/cacheobject.h b/src/unstable/cacheobject.h
index 114a76f..4606493 100644
--- a/src/unstable/cacheobject.h
+++ b/src/unstable/cacheobject.h
@@ -24,6 +24,7 @@ namespace Bu
24 public: 24 public:
25 CacheObject() : 25 CacheObject() :
26 pCache( NULL ), 26 pCache( NULL ),
27 pEntry( NULL ),
27 bChanged( false ) 28 bChanged( false )
28 { 29 {
29 } 30 }
@@ -37,19 +38,23 @@ namespace Bu
37 virtual keytype getKey() const=0; 38 virtual keytype getKey() const=0;
38 virtual int getPersistenceScore() const { return 0; } 39 virtual int getPersistenceScore() const { return 0; }
39 40
40 void lock() 41 void lock() const
41 { 42 {
42 pEntry->lock(); 43 if( pEntry )
44 pEntry->lock();
43 } 45 }
44 46
45 void unlock() 47 void unlock() const
46 { 48 {
47 pEntry->unlock(); 49 if( pEntry )
50 pEntry->unlock();
48 } 51 }
49 52
50 int getRefCount() const 53 int getRefCount() const
51 { 54 {
52 return pEntry->getRefCount(); 55 if( pEntry )
56 return pEntry->getRefCount();
57 return -1;
53 } 58 }
54 59
55 bool hasChanged() const 60 bool hasChanged() const