diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/cache.cpp | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp index 15662af..aa71c39 100644 --- a/src/tests/cache.cpp +++ b/src/tests/cache.cpp | |||
@@ -220,7 +220,7 @@ public: | |||
220 | 220 | ||
221 | virtual ~CachePtr() | 221 | virtual ~CachePtr() |
222 | { | 222 | { |
223 | release(); | 223 | unbind(); |
224 | } | 224 | } |
225 | 225 | ||
226 | const keytype &getKey() const | 226 | const keytype &getKey() const |
@@ -230,31 +230,31 @@ public: | |||
230 | 230 | ||
231 | obtype &operator*() | 231 | obtype &operator*() |
232 | { | 232 | { |
233 | checkRef(); | 233 | bind(); |
234 | return pData; | 234 | return pData; |
235 | } | 235 | } |
236 | 236 | ||
237 | const obtype &operator*() const | 237 | const obtype &operator*() const |
238 | { | 238 | { |
239 | checkRef(); | 239 | bind(); |
240 | return pData; | 240 | return pData; |
241 | } | 241 | } |
242 | 242 | ||
243 | obtype *operator->() | 243 | obtype *operator->() |
244 | { | 244 | { |
245 | checkRef(); | 245 | bind(); |
246 | return pData; | 246 | return pData; |
247 | } | 247 | } |
248 | 248 | ||
249 | const obtype *operator->() const | 249 | const obtype *operator->() const |
250 | { | 250 | { |
251 | checkRef(); | 251 | bind(); |
252 | return pData; | 252 | return pData; |
253 | } | 253 | } |
254 | 254 | ||
255 | MyType operator=( const MyType &rhs ) | 255 | MyType operator=( const MyType &rhs ) |
256 | { | 256 | { |
257 | release(); | 257 | unbind(); |
258 | pCache = rhs.pCache; | 258 | pCache = rhs.pCache; |
259 | kId = rhs.kId; | 259 | kId = rhs.kId; |
260 | pEnt = rhs.pEnt; | 260 | pEnt = rhs.pEnt; |
@@ -275,22 +275,27 @@ public: | |||
275 | return pCache != rhs.pCache || | 275 | return pCache != rhs.pCache || |
276 | kId != rhs.kId; | 276 | kId != rhs.kId; |
277 | } | 277 | } |
278 | |||
279 | void bind() | ||
280 | { | ||
281 | CachePtrInterface<keytype, basetype>::checkRef( pCache, kId, pEnt, pData ); | ||
282 | } | ||
278 | 283 | ||
279 | void release() | 284 | void unbind() |
280 | { | 285 | { |
281 | CachePtrInterface<keytype, basetype>::releaseRef( pCache, pEnt, pData ); | 286 | CachePtrInterface<keytype, basetype>::releaseRef( pCache, pEnt, pData ); |
282 | } | 287 | } |
283 | 288 | ||
284 | void lock() | 289 | void lock() |
285 | { | 290 | { |
286 | checkRef(); | 291 | bind(); |
287 | if( pEnt ) | 292 | if( pEnt ) |
288 | pEnt->lock(); | 293 | pEnt->lock(); |
289 | } | 294 | } |
290 | 295 | ||
291 | void unlock() | 296 | void unlock() |
292 | { | 297 | { |
293 | checkRef(); | 298 | bind(); |
294 | if( pEnt ) | 299 | if( pEnt ) |
295 | pEnt->unlock(); | 300 | pEnt->unlock(); |
296 | } | 301 | } |
@@ -324,12 +329,6 @@ public: | |||
324 | }; | 329 | }; |
325 | 330 | ||
326 | private: | 331 | private: |
327 | void checkRef() | ||
328 | { | ||
329 | CachePtrInterface<keytype, basetype>::checkRef( pCache, kId, pEnt, pData ); | ||
330 | } | ||
331 | |||
332 | private: | ||
333 | CacheBase<keytype, basetype> *pCache; | 332 | CacheBase<keytype, basetype> *pCache; |
334 | mutable keytype kId; | 333 | mutable keytype kId; |
335 | mutable CacheEntry<keytype, basetype> *pEnt; | 334 | mutable CacheEntry<keytype, basetype> *pEnt; |
@@ -658,13 +657,13 @@ int main( int argc, char *argv[] ) | |||
658 | 657 | ||
659 | c._debug(); | 658 | c._debug(); |
660 | 659 | ||
661 | p1.release(); | 660 | p1.unbind(); |
662 | 661 | ||
663 | c._debug(); | 662 | c._debug(); |
664 | 663 | ||
665 | Bu::println("Name: %1").arg( p1->getName() ); | 664 | Bu::println("Name: %1").arg( p1->getName() ); |
666 | 665 | ||
667 | p1.release(); | 666 | p1.unbind(); |
668 | p1.lock(); | 667 | p1.lock(); |
669 | p1.unlock(); | 668 | p1.unlock(); |
670 | 669 | ||