aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-05-01 19:20:21 +0000
committerMike Buland <eichlan@xagasoft.com>2010-05-01 19:20:21 +0000
commitb4f8ebcb496ca231fa737307a0f9757d01e37c7b (patch)
tree57c99b2982b78148fa8b5412280d478a7d3be28e
parentaeb8bee786a9495c78ed94e2a8485ed790714635 (diff)
downloadlibbu++-b4f8ebcb496ca231fa737307a0f9757d01e37c7b.tar.gz
libbu++-b4f8ebcb496ca231fa737307a0f9757d01e37c7b.tar.bz2
libbu++-b4f8ebcb496ca231fa737307a0f9757d01e37c7b.tar.xz
libbu++-b4f8ebcb496ca231fa737307a0f9757d01e37c7b.zip
Cache fixes.
-rw-r--r--src/cache.h33
-rw-r--r--src/cachecalc.h1
-rw-r--r--src/cachestorenids.h1
-rw-r--r--src/tests/cache.cpp10
4 files changed, 25 insertions, 20 deletions
diff --git a/src/cache.h b/src/cache.h
index 1753407..896aa71 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -112,11 +112,6 @@ namespace Bu
112 return pData != NULL; 112 return pData != NULL;
113 } 113 }
114 114
115 operator bool() const
116 {
117 return isBound() && isValid();
118 }
119
120 const keytype &getKey() const 115 const keytype &getKey() const
121 { 116 {
122 return kId; 117 return kId;
@@ -297,7 +292,7 @@ namespace Bu
297 try { 292 try {
298 if( hEnt.get( cId ).iRefs > 0 ) 293 if( hEnt.get( cId ).iRefs > 0 )
299 { 294 {
300 printf("Shouldn't delete, references still exist!\n"); 295 printf("Shouldn't unload, references still exist!\n");
301 return; 296 return;
302 } 297 }
303 } 298 }
@@ -317,24 +312,22 @@ namespace Bu
317 void erase( const keytype &cId ) 312 void erase( const keytype &cId )
318 { 313 {
319 TRACE( cId ); 314 TRACE( cId );
320 if( hEnt.has( cId ) ) 315 try {
321 { 316 if( hEnt.get( cId ).iRefs > 0 )
322 try { 317 {
323 if( hEnt.get( cId ).iRefs > 0 ) 318 printf("Shouldn't erase, references still exist!\n");
324 { 319 return;
325 printf("Shouldn't delete, references still exist!\n");
326 return;
327 }
328 }
329 catch( Bu::HashException &e ) {
330 get( cId );
331 } 320 }
332 321 }
333 pCalc->onUnload( hEnt.get( cId ).pData, cId ); 322 catch( Bu::HashException &e ) {
334 pStore->destroy( hEnt.get( cId ).pData, cId ); 323 get( cId );
335 } 324 }
336 325
326 obtype *pObj = hEnt.get( cId ).pData;
327 pCalc->onDestroy( pObj, cId );
337 hEnt.erase( cId ); 328 hEnt.erase( cId );
329
330 pStore->destroy( pObj, cId );
338 } 331 }
339 332
340 typedef Bu::List<keytype> KeyList; 333 typedef Bu::List<keytype> KeyList;
diff --git a/src/cachecalc.h b/src/cachecalc.h
index c9968dc..d0729a9 100644
--- a/src/cachecalc.h
+++ b/src/cachecalc.h
@@ -36,6 +36,7 @@ namespace Bu
36 36
37 virtual void onLoad( obtype *pSrc, const keytype &key )=0; 37 virtual void onLoad( obtype *pSrc, const keytype &key )=0;
38 virtual void onUnload( obtype *pSrc, const keytype &key )=0; 38 virtual void onUnload( obtype *pSrc, const keytype &key )=0;
39 virtual void onDestroy( obtype *pSrc, const keytype &key )=0;
39 virtual bool shouldSync( obtype *pSrc, const keytype &key, 40 virtual bool shouldSync( obtype *pSrc, const keytype &key,
40 time_t tLastSync )=0; 41 time_t tLastSync )=0;
41 virtual void onTick() { }; 42 virtual void onTick() { };
diff --git a/src/cachestorenids.h b/src/cachestorenids.h
index 54129b0..f413bd0 100644
--- a/src/cachestorenids.h
+++ b/src/cachestorenids.h
@@ -122,6 +122,7 @@ namespace Bu
122 nStore.deleteStream( iStream ); 122 nStore.deleteStream( iStream );
123 hId.erase( key ); 123 hId.erase( key );
124 delete pObj; 124 delete pObj;
125 sync();
125 } 126 }
126 127
127 virtual bool has( const keytype &key ) 128 virtual bool has( const keytype &key )
diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp
index 97aba4a..3470ecb 100644
--- a/src/tests/cache.cpp
+++ b/src/tests/cache.cpp
@@ -41,6 +41,12 @@ public:
41 TRACE( i ); 41 TRACE( i );
42 iInt = i; 42 iInt = i;
43 } 43 }
44
45 long getKey() const
46 {
47 TRACE( i );
48 return iInt;
49 }
44 50
45 int getInt() 51 int getInt()
46 { 52 {
@@ -177,6 +183,10 @@ public:
177 { 183 {
178 } 184 }
179 185
186 virtual void onDestroy( Bob *, const long & )
187 {
188 }
189
180 virtual bool shouldSync( Bob *, const long &, time_t ) 190 virtual bool shouldSync( Bob *, const long &, time_t )
181 { 191 {
182 return false; 192 return false;