Changeset 4847 for branches/erijo-dev

Show
Ignore:
Timestamp:
01/30/07 06:44:33 (22 months ago)
Author:
erijo
Message:

Fix bug in TMutexLocker where Locked was set to true after the mutex
was unlocked. Updated unittest to fail if this would happen again.

Location:
branches/erijo-dev/licq
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/erijo-dev/licq/CMakeLists.txt

    r4835 r4847  
    99    FORCE) 
    1010endif (NOT CMAKE_BUILD_TYPE) 
     11 
     12# Define DEBUG when doing debug builds. 
     13set(CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG" CACHE STRING 
     14  "Flags used by the C++ compiler during debug builds." FORCE) 
    1115 
    1216# Enables testing with ctest and adds a "test" target (make test) 
  • branches/erijo-dev/licq/src/utils/mutex.cpp

    r4827 r4847  
    2525  : Locked(false) 
    2626{ 
     27#if defined(DEBUG) && defined(__USE_GNU) 
     28  pthread_mutexattr_t attr; 
     29  pthread_mutexattr_init(&attr); 
     30  pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP); 
     31  pthread_mutex_init(&Mutex, &attr); 
     32  pthread_mutexattr_destroy(&attr); 
     33#else 
     34# ifdef DEBUG 
     35#  warning "Not using error checking mutex since __USE_GNU is not defined." 
     36# endif 
    2737  pthread_mutex_init(&Mutex, NULL); 
     38#endif 
    2839} 
    2940 
  • branches/erijo-dev/licq/src/utils/mutexlocker.cpp

    r4827 r4847  
    4545  assert(Mutex != NULL); 
    4646  Mutex->unlock(); 
    47   Locked = true; 
     47  Locked = false; 
    4848} 
    4949 
  • branches/erijo-dev/licq/src/utils/tests/mutexlockertest.cpp

    r4827 r4847  
    4545 
    4646  BOOST_CHECK_EQUAL(mutex.isLocked(), false); 
     47 
     48  // Check that mutex isn't unlocked in locker's destructor when mutex isn't locked. 
     49  // This test requires that TMutex is built with DEBUG (and __USE_GNU) defined. 
     50  { 
     51    TMutexLocker locker(&mutex); 
     52    locker.lock(); 
     53 
     54    BOOST_CHECK_EQUAL(mutex.isLocked(), true); 
     55    locker.unlock(); 
     56    BOOST_CHECK_EQUAL(mutex.isLocked(), false); 
     57  } 
     58 
     59  BOOST_CHECK_EQUAL(mutex.isLocked(), false); 
    4760}