diff options
author | Mike Buland <eichlan@xagasoft.com> | 2015-08-25 21:47:49 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2015-08-25 21:47:49 +0000 |
commit | 6d5135aa23f2ae12d953ceab1c1d01e003a55be1 (patch) | |
tree | 75ad30019a6780bb76e8adc0c744b4a747193f40 | |
parent | 04f68d35183bb98c04f09b077e650cf90ff72139 (diff) | |
download | libbu++-6d5135aa23f2ae12d953ceab1c1d01e003a55be1.tar.gz libbu++-6d5135aa23f2ae12d953ceab1c1d01e003a55be1.tar.bz2 libbu++-6d5135aa23f2ae12d953ceab1c1d01e003a55be1.tar.xz libbu++-6d5135aa23f2ae12d953ceab1c1d01e003a55be1.zip |
Added more lock/unlock features to the cache Lockers. That...was a weird
sentence, but it's true. Also, oddly enough, Lockers aren't thread-safe, but
they shouldn't ever have to be. Figure that one out!
Diffstat (limited to '')
-rw-r--r-- | src/unstable/cachebase.h | 8 | ||||
-rw-r--r-- | src/unstable/cacheobject.h | 20 |
2 files changed, 27 insertions, 1 deletions
diff --git a/src/unstable/cachebase.h b/src/unstable/cachebase.h index d5b4382..2e0f24f 100644 --- a/src/unstable/cachebase.h +++ b/src/unstable/cachebase.h | |||
@@ -351,6 +351,14 @@ namespace Bu | |||
351 | bLocked = false; | 351 | bLocked = false; |
352 | } | 352 | } |
353 | 353 | ||
354 | void lock() | ||
355 | { | ||
356 | if( bLocked ) | ||
357 | return; | ||
358 | rPtr.lock(); | ||
359 | bLocked = true; | ||
360 | } | ||
361 | |||
354 | private: | 362 | private: |
355 | MyType &rPtr; | 363 | MyType &rPtr; |
356 | bool bLocked; | 364 | bool bLocked; |
diff --git a/src/unstable/cacheobject.h b/src/unstable/cacheobject.h index e519a9c..080312f 100644 --- a/src/unstable/cacheobject.h +++ b/src/unstable/cacheobject.h | |||
@@ -69,18 +69,36 @@ namespace Bu | |||
69 | { | 69 | { |
70 | public: | 70 | public: |
71 | Locker( const MyType *pObj ) : | 71 | Locker( const MyType *pObj ) : |
72 | pObj( pObj ) | 72 | pObj( pObj ), |
73 | bLocked( true ) | ||
73 | { | 74 | { |
74 | pObj->lock(); | 75 | pObj->lock(); |
75 | } | 76 | } |
76 | 77 | ||
77 | ~Locker() | 78 | ~Locker() |
78 | { | 79 | { |
80 | unlock(); | ||
81 | } | ||
82 | |||
83 | void unlock() | ||
84 | { | ||
85 | if( !bLocked ) | ||
86 | return; | ||
79 | pObj->unlock(); | 87 | pObj->unlock(); |
88 | bLocked = false; | ||
89 | } | ||
90 | |||
91 | void lock() | ||
92 | { | ||
93 | if( bLocked ) | ||
94 | return; | ||
95 | pObj->lock(); | ||
96 | bLocked = true; | ||
80 | } | 97 | } |
81 | 98 | ||
82 | private: | 99 | private: |
83 | const MyType *pObj; | 100 | const MyType *pObj; |
101 | bool bLocked; | ||
84 | }; | 102 | }; |
85 | 103 | ||
86 | protected: | 104 | protected: |