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:
Lewis Baker 2018-08-03 08:17:55 -07:00
parent c6d5f6a738
commit d4c106635b

View file

@ -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();
}
}
}