Make spin_mutex avoid cache contention while waiting for lock.
Don't write to flag until it looks like the lock has become available. This should reduce the cache-line unnecessarily jumping between cores when under contention.
This commit is contained in:
parent
c6d5f6a738
commit
d4c106635b
|
@ -23,7 +23,10 @@ namespace cppcoro
|
|||
spin_wait wait;
|
||||
while (!try_lock())
|
||||
{
|
||||
wait.spin_one();
|
||||
while (m_isLocked.load(std::memory_order_relaxed))
|
||||
{
|
||||
wait.spin_one();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue