Mutex deadlock detection in debug
Add a debug implementation to Mutex that detects deadlocks caused by calling lock twice in a single thread.
This commit is contained in:
committed by
GitHub
parent
116b770809
commit
f38fd388f8
@@ -161,12 +161,20 @@ const WindowsImpl = struct {
|
||||
}
|
||||
}
|
||||
|
||||
if (comptime builtin.mode == .Debug) {
|
||||
// The internal state of the DebugMutex needs to be handled here as well.
|
||||
mutex.impl.locking_thread.store(0, .Unordered);
|
||||
}
|
||||
const rc = os.windows.kernel32.SleepConditionVariableSRW(
|
||||
&self.condition,
|
||||
&mutex.impl.srwlock,
|
||||
if (comptime builtin.mode == .Debug) &mutex.impl.impl.srwlock else &mutex.impl.srwlock,
|
||||
timeout_ms,
|
||||
0, // the srwlock was assumed to acquired in exclusive mode not shared
|
||||
);
|
||||
if (comptime builtin.mode == .Debug) {
|
||||
// The internal state of the DebugMutex needs to be handled here as well.
|
||||
mutex.impl.locking_thread.store(std.Thread.getCurrentId(), .Unordered);
|
||||
}
|
||||
|
||||
// Return error.Timeout if we know the timeout elapsed correctly.
|
||||
if (rc == os.windows.FALSE) {
|
||||
|
||||
Reference in New Issue
Block a user