X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fthread%2F__lock.c;h=0874c04a4c0a81a9fa0dc032479ec18cec81d8aa;hb=78a8ef47c4d92b7680c52a85f80a81e29da86bb9;hp=21c85fc0636f71f6eb715459590f78ec4e0aaac5;hpb=6232b96f5153d0b718054a8bc569fcd7d596bab2;p=musl diff --git a/src/thread/__lock.c b/src/thread/__lock.c index 21c85fc0..0874c04a 100644 --- a/src/thread/__lock.c +++ b/src/thread/__lock.c @@ -2,10 +2,14 @@ void __lock(volatile int *l) { - int spins=10000; - /* Do not use futexes because we insist that unlocking is a simple - * assignment to optimize non-pathological code with no contention. */ - while (a_xchg(l, 1)) - if (spins) spins--, a_spin(); - else __syscall(SYS_sched_yield); + if (libc.threads_minus_1) + while (a_swap(l, 1)) __wait(l, l+1, 1, 1); +} + +void __unlock(volatile int *l) +{ + if (l[0]) { + a_store(l, 0); + if (l[1]) __wake(l, 1, 1); + } }