Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/fibers/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <silk/util/spinlock.h>

#include <atomic>
#include <format>

namespace silk
{
Expand Down Expand Up @@ -39,6 +40,8 @@ void FiberMutex::lock() noexcept
State currentState;
currentState.raw = state.load(std::memory_order_relaxed);

ASSERT_DEBUG(currentState.owner != reinterpret_cast<uint64_t>(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.
Expand All @@ -62,6 +65,11 @@ void FiberMutex::unlock() noexcept
{
State currentState;
currentState.raw = state.load(std::memory_order_relaxed);

ASSERT_DEBUG(
currentState.owner == reinterpret_cast<uint64_t>(FiberScheduler::getCurrentFiber()),
"FiberMutex::unlock called by non-owner fiber");

for (;;)
{
ASSERT(currentState.raw);
Expand Down
Loading