ref: 1edee0e32036f4d1cb23e94cab7b8f72f6ee9193
parent: 28c95a0761154c121b49e54912f0c45dc7dffec0
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Sep 16 09:40:31 EDT 2015
Rename 'Sleep' to 'Lockedcontended'. Clearer meaning.
--- a/lib/thread/mutex+linux.myr
+++ b/lib/thread/mutex+linux.myr
@@ -16,7 +16,7 @@
const Unlocked = 0
const Locked = 1
-const Sleep = 2
+const Lockedcontended = 2
generic Zptr = 0 castto(@a#)
var nspin = 1 /* FIXME: pick a sane number, based on CPU count */
@@ -38,12 +38,12 @@
/* contended: we set the lock _state to sleep */
if c == Locked
- c = xchg(&mtx._state, Sleep)
+ c = xchg(&mtx._state, Lockedcontended)
;;
while c != Unlocked
- sys.futex(&mtx._state, sys.Futexwait | sys.Futexpriv, Sleep, Zptr, Zptr, 0)
- c = xchg(&mtx._state, 2)
+ sys.futex(&mtx._state, sys.Futexwait | sys.Futexpriv, Lockedcontended, Zptr, Zptr, 0)
+ c = xchg(&mtx._state, Lockedcontended)
;;
}
@@ -53,7 +53,7 @@
const mtxunlock = {mtx
/* uncontended sleep means we can just unlock and move on */
- if mtx._state == Sleep
+ if mtx._state == Lockedcontended
mtx._state = Unlocked
elif xchg(&mtx._state, Unlocked) == Locked
->
@@ -62,7 +62,7 @@
for var i = 0; i < nspin; i++
if mtx._state != Unlocked
/* there might have been waiters, but we set the _state to unlocked */
- if xcas(&mtx._state, Locked, Sleep) == Sleep
+ if xcas(&mtx._state, Locked, Lockedcontended) == Contendedlock
->
;;
;;