X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fthread%2F__lock.c;h=2f345ae7af02153c1bffbd5cbfc0f0be860127a6;hp=5ba5dc5ee618a2fce5561f5a0f0a3e1709838719;hb=HEAD;hpb=e7655ed37bc9c2d79d921af4f287ee5cf2788661 diff --git a/src/thread/__lock.c b/src/thread/__lock.c index 5ba5dc5e..2f345ae7 100644 --- a/src/thread/__lock.c +++ b/src/thread/__lock.c @@ -1,32 +1,12 @@ #include "pthread_impl.h" -void __lock_2(volatile int *l) -{ - if (!__syscall(SYS_futex, l, FUTEX_LOCK_PI, 0, 0)) - return; - int old, tid = __pthread_self()->tid|INT_MIN; - while ((old = a_cas(l, 0, tid))) { - a_cas(l, old, old|INT_MIN); - __syscall(SYS_futex, l, FUTEX_WAIT, old|INT_MIN, 0); - } -} - void __lock(volatile int *l) { - if (a_cas(l, 0, __pthread_self()->tid)) __lock_2(l); -} - -void __unlock_2(volatile int *l) -{ - if (__syscall(SYS_futex, l, FUTEX_UNLOCK_PI)) { - *l = 0; - __syscall(SYS_futex, l, FUTEX_WAKE, 1); - } + while (a_swap(l, 1)) __wait(l, l+1, 1, 1); } void __unlock(volatile int *l) { - int old = *l; - if (!(old & INT_MIN) && a_cas(l, old, 0)==old) return; - __unlock_2(l); + a_store(l, 0); + if (l[1]) __wake(l, 1, 1); }