Changeset 4872 for branches/erijo-dev

Show
Ignore:
Timestamp:
03/20/07 05:21:24 (21 months ago)
Author:
erijo
Message:

Lock mutex (per default) when creating a TMutexLocker

Location:
branches/erijo-dev/licq/src/utils
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • branches/erijo-dev/licq/src/utils/mutexlocker.cpp

    r4847 r4872  
    2222#include <cassert> 
    2323 
    24 Licq::TMutexLocker::TMutexLocker(TMutex* mutex) 
     24Licq::TMutexLocker::TMutexLocker(TMutex* mutex, TCreateOption option) 
    2525  : Mutex(mutex), Locked(false) 
    2626{ 
    27   // Empty 
     27  if (option == CREATE_LOCKED) 
     28    lock(); 
    2829} 
    2930 
  • branches/erijo-dev/licq/src/utils/mutexlocker.h

    r4839 r4872  
    4848      { 
    4949        TMutexLocker locker(&Mutex); 
    50         locker.lock(); 
    5150        return Counter++; 
    5251      } 
     
    6160 
    6261public: 
     62  enum TCreateOption { CREATE_LOCKED, CREATE_UNLOCKED }; 
    6363  /** \brief Create a new TMutexLocker. 
    6464 
    65       Does \b not lock \a mutex. 
    66  
    6765      \param[in] mutex Must be a mutex \b not locked by this thread. 
     66      \param[in] option Lock the mutex if option is CREATE_LOCKED. 
    6867  */ 
    69   TMutexLocker(TMutex* mutex); 
     68  TMutexLocker(TMutex* mutex, TCreateOption option = CREATE_LOCKED); 
    7069 
    7170  /// Unlock the mutex if it was previous locked in lock() or tryLock(). 
  • branches/erijo-dev/licq/src/utils/tests/mutexlockertest.cpp

    r4847 r4872  
    3333  { 
    3434    TMutexLocker locker(&mutex); 
     35    BOOST_CHECK_EQUAL(mutex.isLocked(), true); 
     36  } 
     37 
     38  BOOST_CHECK_EQUAL(mutex.isLocked(), false); 
     39 
     40  { 
     41    TMutexLocker locker(&mutex, TMutexLocker::CREATE_UNLOCKED); 
    3542    BOOST_CHECK_EQUAL(mutex.isLocked(), false); 
    3643 
     
    4956  // This test requires that TMutex is built with DEBUG (and __USE_GNU) defined. 
    5057  { 
    51     TMutexLocker locker(&mutex); 
     58    TMutexLocker locker(&mutex, TMutexLocker::CREATE_UNLOCKED); 
    5259    locker.lock(); 
    5360