Skip to content

Commit fed81c2

Browse files
committed
rt: Add some lock_and_signal assertions
Assert that locks are not reentered on the same thread, unlocked by a different thread, or deleted while locked.
1 parent 9f49293 commit fed81c2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/rt/sync/lock_and_signal.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ lock_and_signal::lock_and_signal()
4343
#endif
4444

4545
lock_and_signal::~lock_and_signal() {
46+
assert(_holding_thread == INVALID_THREAD);
4647
#if defined(__WIN32__)
4748
CloseHandle(_event);
4849
DeleteCriticalSection(&_cs);
@@ -53,6 +54,7 @@ lock_and_signal::~lock_and_signal() {
5354
}
5455

5556
void lock_and_signal::lock() {
57+
assert(!lock_held_by_current_thread());
5658
#if defined(__WIN32__)
5759
EnterCriticalSection(&_cs);
5860
_holding_thread = GetCurrentThreadId();
@@ -63,6 +65,7 @@ void lock_and_signal::lock() {
6365
}
6466

6567
void lock_and_signal::unlock() {
68+
assert(lock_held_by_current_thread());
6669
_holding_thread = INVALID_THREAD;
6770
#if defined(__WIN32__)
6871
LeaveCriticalSection(&_cs);
@@ -81,9 +84,11 @@ void lock_and_signal::wait() {
8184
LeaveCriticalSection(&_cs);
8285
WaitForSingleObject(_event, INFINITE);
8386
EnterCriticalSection(&_cs);
87+
assert(_holding_thread == INVALID_THREAD);
8488
_holding_thread = GetCurrentThreadId();
8589
#else
8690
CHECKED(pthread_cond_wait(&_cond, &_mutex));
91+
assert(_holding_thread == INVALID_THREAD);
8792
_holding_thread = pthread_self();
8893
#endif
8994
}

0 commit comments

Comments
 (0)