mirror of
https://github.com/fluencelabs/musl
synced 2025-06-29 14:42:01 +00:00
refrain from spinning on locks when there is already a waiter
if there is already a waiter for a lock, spinning on the lock is essentially an attempt to steal it from whichever waiter would obtain it via any priority rules in place, and is therefore undesirable. in the current implementation, there is always an inherent race window at unlock during which a newly-arriving thread may steal the lock from the existing waiters, but we should aim to keep this window minimal rather than enlarging it.
This commit is contained in:
@ -4,7 +4,7 @@ void __wait(volatile int *addr, volatile int *waiters, int val, int priv)
|
||||
{
|
||||
int spins=100;
|
||||
if (priv) priv = 128;
|
||||
while (spins--) {
|
||||
while (spins-- && (!waiters || !*waiters)) {
|
||||
if (*addr==val) a_spin();
|
||||
else return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user