From 51eef132bb2bb67e658756eaebeae5e52c13de98 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 18 Jul 2013 02:09:29 +0000 Subject: Fixed caching changed issue. The cache now marks objects as unchanged for you after they are saved. It needs some more testing, but the theory is sound. --- src/tests/cache.cpp | 5 +++-- src/unstable/cachebase.h | 7 +++++-- src/unstable/uuid.cpp | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp index 20b384e..7982b2d 100644 --- a/src/tests/cache.cpp +++ b/src/tests/cache.cpp @@ -171,6 +171,8 @@ namespace Bu default: throw Bu::ExceptionBase("Flagrant error! Invalid type!"); } + + return NULL; } } @@ -179,7 +181,7 @@ typedef Bu::CachePtr SomethingAPtr; typedef Bu::CachePtr SomethingBPtr; typedef Bu::MyriadCache SomethingCache; -int main( int argc, char *argv[] ) +int main( int, char *[] ) { Bu::File fStore("test.myr", Bu::File::Create|Bu::File::ReadWrite); SomethingCache c( fStore ); @@ -196,7 +198,6 @@ int main( int argc, char *argv[] ) SomethingCache::KeyList lKeys = c.getKeys(); Bu::println("Count: %1").arg( lKeys.getSize() ); - int j = 0; for( SomethingCache::KeyList::iterator i = lKeys.begin(); i; i++ ) { Bu::println(" - %1: '%2'").arg( *i ).arg( c.get( *i )->toString() ); diff --git a/src/unstable/cachebase.h b/src/unstable/cachebase.h index 6cc3e77..af2884c 100644 --- a/src/unstable/cachebase.h +++ b/src/unstable/cachebase.h @@ -184,7 +184,8 @@ namespace Bu pEnt( rhs.pEnt ), pData( rhs.pData ) { - pEnt->incRef(); + if( pEnt ) + pEnt->incRef(); } virtual ~CachePtr() @@ -228,7 +229,8 @@ namespace Bu kId = rhs.kId; pEnt = rhs.pEnt; pData = rhs.pData; - pEnt->incRef(); + if( pEnt ) + pEnt->incRef(); return *this; } @@ -513,6 +515,7 @@ namespace Bu Entry *pEnt = hCacheEntry.get( i.getKey() ); Bu::MutexLocker ml( pEnt->getMutex() ); _save( pEnt->getPtr() ); + pEnt->getPtr()->changed( false ); } hChanged.clear(); } diff --git a/src/unstable/uuid.cpp b/src/unstable/uuid.cpp index a93f713..304ea4a 100644 --- a/src/unstable/uuid.cpp +++ b/src/unstable/uuid.cpp @@ -77,6 +77,7 @@ int Bu::Uuid::getVersion() void Bu::Uuid::clear() { + memset( data, 0, 16 ); data[7] = msb(0); } -- cgit v1.2.3