Changeset 45:b978a5b780d9 in rrlib_util


Ignore:
Timestamp:
24.01.2012 10:51:54 (8 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Children:
47:d5a2f50272a1, 48:0dc60258b3b2
Phase:
public
Message:

Fixed multithreading issue with Longevity singletons

File:
1 edited

Legend:

Unmodified
Added
Removed
  • patterns/singleton/tLifetimeTracker.h

    r44 r45  
    117117inline void SetLongevity(unsigned int longevity, void (*destroy_instance)()) 
    118118{ 
     119  static std::mutex mutex; 
     120  std::unique_lock<std::mutex> lock(mutex); 
     121 
    119122  std::auto_ptr<tLifetimeTracker> p(new tLifetimeTracker(longevity, destroy_instance)); 
    120123 
    121   auto position = std::upper_bound(tLifetimeTrackerList::Instance().begin(), tLifetimeTrackerList::Instance().end(), p.get(), tLifetimeTracker::SmallerFirst); 
    122   tLifetimeTrackerList::Instance().insert(position, p.get()); 
     124  auto &tracker_list = tLifetimeTrackerList::Instance(); 
     125  auto position = std::upper_bound(tracker_list.begin(), tracker_list.end(), p.get(), tLifetimeTracker::SmallerFirst); 
     126  tracker_list.insert(position, p.get()); 
    123127 
    124128  p.release(); 
Note: See TracChangeset for help on using the changeset viewer.