Changeset 3681dd for src/CodePatterns
- Timestamp:
- Oct 30, 2015, 11:44:33 AM (10 years ago)
- Children:
- 315a1e
- Parents:
- 6e2f3b
- git-author:
- Frederik Heber <heber@…> (10/30/15 11:40:59)
- git-committer:
- Frederik Heber <heber@…> (10/30/15 11:44:33)
- File:
-
- 1 edited
-
src/CodePatterns/Cacheable.hpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/CodePatterns/Cacheable.hpp
r6e2f3b r3681dd 18 18 #include <boost/function.hpp> 19 19 #include <boost/shared_ptr.hpp> 20 #include <boost/thread/locks.hpp> 21 #include <boost/thread/recursive_mutex.hpp> 20 22 21 23 #include "CodePatterns/Assert.hpp" … … 166 168 state_ptr validState; 167 169 // destroyed state is not predefined, because we rarely enter that state and never leave 170 171 //!> mutex to ensure access is only per-thread 172 mutable boost::recursive_mutex ownerLock; 168 173 169 174 const Observable * const owner; … … 195 200 // we sign on with the best(=lowest) priority, so cached values are recalculated before 196 201 // anybody else might ask for updated values 202 boost::lock_guard<boost::recursive_mutex> guard(ownerLock); 197 203 if (owner != NULL) { 198 204 if (channels.empty()) { … … 215 221 const T Cacheable<T>::operator*() const{ 216 222 // we can only use the cacheable when the owner is not changing at the moment 223 boost::lock_guard<boost::recursive_mutex> guard(ownerLock); 217 224 if ((owner == NULL) || (!owner->isBlocked())) { 218 225 return state->getValue(); … … 226 233 Cacheable<T>::~Cacheable() 227 234 { 235 boost::lock_guard<boost::recursive_mutex> guard(ownerLock); 228 236 if (owner != NULL) { 229 237 if (channels.empty()) { … … 252 260 template<typename T> 253 261 void Cacheable<T>::recieveNotification(Observable *publisher, Notification_ptr notification) { 262 boost::lock_guard<boost::recursive_mutex> guard(ownerLock); 254 263 if (publisher == owner) { 255 264 ASSERT( !channels.empty(), … … 266 275 state_ptr destroyed = state_ptr(new DestroyedState(this)); 267 276 switchState(destroyed); 277 boost::lock_guard<boost::recursive_mutex> guard(ownerLock); 278 const_cast<const Observable *&>(owner) = NULL; 268 279 } 269 280
Note:
See TracChangeset
for help on using the changeset viewer.
