From 37cf30d88dee18eda1e613342dccc34a20062ef3 Mon Sep 17 00:00:00 2001 From: Vadim Skipin Date: Wed, 6 May 2026 20:30:24 +0000 Subject: [PATCH] Check mutex owner in debug build --- src/fibers/mutex.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fibers/mutex.cpp b/src/fibers/mutex.cpp index f0acd99..7bbcae4 100644 --- a/src/fibers/mutex.cpp +++ b/src/fibers/mutex.cpp @@ -5,6 +5,7 @@ #include #include +#include namespace silk { @@ -39,6 +40,8 @@ void FiberMutex::lock() noexcept State currentState; currentState.raw = state.load(std::memory_order_relaxed); + ASSERT_DEBUG(currentState.owner != reinterpret_cast(FiberScheduler::getCurrentFiber()), "FiberMutex is not reentrant"); + // Spin briefly before suspending: if the owner is on another CPU and releases // within ~500 ns, we avoid the full scheduler wakeup path. // Skip if there are already waiters in the queue. @@ -62,6 +65,11 @@ void FiberMutex::unlock() noexcept { State currentState; currentState.raw = state.load(std::memory_order_relaxed); + + ASSERT_DEBUG( + currentState.owner == reinterpret_cast(FiberScheduler::getCurrentFiber()), + "FiberMutex::unlock called by non-owner fiber"); + for (;;) { ASSERT(currentState.raw);