aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2013-07-03 19:55:56 +0000
committerMike Buland <eichlan@xagasoft.com>2013-07-03 19:55:56 +0000
commit65cc54be0a14e627938731ff8deefea61c2c1cfa (patch)
tree8c52df22ffba1a21bb3b849660adf12ebd185208
parent7b1f2da0d83d4e01a8d8a32e02bea6b33c61e3f4 (diff)
downloadlibbu++-65cc54be0a14e627938731ff8deefea61c2c1cfa.tar.gz
libbu++-65cc54be0a14e627938731ff8deefea61c2c1cfa.tar.bz2
libbu++-65cc54be0a14e627938731ff8deefea61c2c1cfa.tar.xz
libbu++-65cc54be0a14e627938731ff8deefea61c2c1cfa.zip
Modified the Bu::CacheBase API, what was erase is eraseNow, and erase is about
to be re-engineered to actually do a lazy erase like removing an iNode in a posix filesystem. While the file remains open it exists, but the references visible to the user on disk are gone.
-rw-r--r--src/tests/random.cpp7
-rw-r--r--src/unstable/cachebase.h21
2 files changed, 28 insertions, 0 deletions
diff --git a/src/tests/random.cpp b/src/tests/random.cpp
index d7b94ce..07a2a06 100644
--- a/src/tests/random.cpp
+++ b/src/tests/random.cpp
@@ -41,6 +41,13 @@ void coverage()
41 41
42int main() 42int main()
43{ 43{
44 RandomCmwc c( 123456 );
45 for( int j = 0; j < 10; j++ )
46 {
47 println("%1").arg( c.rand() );
48 }
49 return 0;
50
44 coverage<RandomBasic>(); 51 coverage<RandomBasic>();
45 coverage<RandomCmwc>(); 52 coverage<RandomCmwc>();
46 coverage<RandomSystem>(); 53 coverage<RandomSystem>();
diff --git a/src/unstable/cachebase.h b/src/unstable/cachebase.h
index 270c2df..6cc3e77 100644
--- a/src/unstable/cachebase.h
+++ b/src/unstable/cachebase.h
@@ -393,8 +393,27 @@ namespace Bu
393 return CachePtr<keytype, castto, obtype>( this, ptr.kId ); 393 return CachePtr<keytype, castto, obtype>( this, ptr.kId );
394 } 394 }
395 395
396 /**
397 * Removes an item from the cache.
398 * This routine calls eraseNow for now. Later the intention is that
399 * this function will always succeed. It will remove the object from
400 * the backing store and the active tables. It will not be able to
401 * be requested again, and all changes will be ignored. When the
402 * object's last references are released the memory will be freed
403 * automatically.
404 */
396 void erase( const keytype &key ) 405 void erase( const keytype &key )
397 { 406 {
407 eraseNow( key );
408 }
409
410 /**
411 * Removes an item from the cache and frees memory immediately.
412 * The object in question cannot have any active references in order
413 * for this to succeed, otherwise it will throw an exception.
414 */
415 void eraseNow( const keytype &key )
416 {
398 Bu::ReadWriteMutex::WriteLocker wl( mCacheEntry ); 417 Bu::ReadWriteMutex::WriteLocker wl( mCacheEntry );
399 if( hCacheEntry.has( key ) ) 418 if( hCacheEntry.has( key ) )
400 { 419 {
@@ -456,6 +475,8 @@ namespace Bu
456 Entry *pEnt = new Entry( pObject ); 475 Entry *pEnt = new Entry( pObject );
457 mCacheEntry.lockWrite(); 476 mCacheEntry.lockWrite();
458 hCacheEntry.insert( pObject->getKey(), pEnt ); 477 hCacheEntry.insert( pObject->getKey(), pEnt );
478 if( pObject->hasChanged() )
479 hChanged.insert( pObject->getKey(), true );
459 mCacheEntry.unlockWrite(); 480 mCacheEntry.unlockWrite();
460 _create( pObject ); 481 _create( pObject );
461 pObject->setCache( this, pEnt ); 482 pObject->setCache( this, pEnt );