Source

Branch

1/ @SebAaltonen

Don’t use spinlock for waits. Use spinlock only to guard something that is guaranteed to return quickly. If you have an operation that is often fast but sometimes slow, use two stage spinlock with internal OS mutex.

2/ @SebAaltonen

Naive (bad) vs optimized (good) performance. See above post for code.