From 7b1f2da0d83d4e01a8d8a32e02bea6b33c61e3f4 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 8 Apr 2013 12:10:31 +0000 Subject: 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. --- src/unstable/cacheobject.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') 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 public: CacheObject() : pCache( NULL ), + pEntry( NULL ), bChanged( false ) { } @@ -37,19 +38,23 @@ namespace Bu virtual keytype getKey() const=0; virtual int getPersistenceScore() const { return 0; } - void lock() + void lock() const { - pEntry->lock(); + if( pEntry ) + pEntry->lock(); } - void unlock() + void unlock() const { - pEntry->unlock(); + if( pEntry ) + pEntry->unlock(); } int getRefCount() const { - return pEntry->getRefCount(); + if( pEntry ) + return pEntry->getRefCount(); + return -1; } bool hasChanged() const -- cgit v1.2.3