Skip to content

Commit

Permalink
rt: Add some lock_and_signal assertions
Browse files Browse the repository at this point in the history
Assert that locks are not reentered on the same thread, unlocked by a
different thread, or deleted while locked.
  • Loading branch information
cpeterso committed Feb 20, 2012
1 parent 9f49293 commit fed81c2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/rt/sync/lock_and_signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ lock_and_signal::lock_and_signal()
#endif

lock_and_signal::~lock_and_signal() {
assert(_holding_thread == INVALID_THREAD);
#if defined(__WIN32__)
CloseHandle(_event);
DeleteCriticalSection(&_cs);
Expand All @@ -53,6 +54,7 @@ lock_and_signal::~lock_and_signal() {
}

void lock_and_signal::lock() {
assert(!lock_held_by_current_thread());
#if defined(__WIN32__)
EnterCriticalSection(&_cs);
_holding_thread = GetCurrentThreadId();
Expand All @@ -63,6 +65,7 @@ void lock_and_signal::lock() {
}

void lock_and_signal::unlock() {
assert(lock_held_by_current_thread());
_holding_thread = INVALID_THREAD;
#if defined(__WIN32__)
LeaveCriticalSection(&_cs);
Expand All @@ -81,9 +84,11 @@ void lock_and_signal::wait() {
LeaveCriticalSection(&_cs);
WaitForSingleObject(_event, INFINITE);
EnterCriticalSection(&_cs);
assert(_holding_thread == INVALID_THREAD);
_holding_thread = GetCurrentThreadId();
#else
CHECKED(pthread_cond_wait(&_cond, &_mutex));
assert(_holding_thread == INVALID_THREAD);
_holding_thread = pthread_self();
#endif
}
Expand Down

0 comments on commit fed81c2

Please sign in to comment.