summaryrefslogtreecommitdiff
path: root/lib/thread
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2015-09-16 23:13:39 -0700
committerOri Bernstein <ori@eigenstate.org>2015-09-16 23:13:39 -0700
commit1882f1be4849ab34aa289e0f74fd6ffadb31a7fa (patch)
treed269163d0e3e1a78e74cb4551510f654c8bce1e4 /lib/thread
parent95ba2c2257e56e80fe01cfcce5b533e4b4e54e7b (diff)
downloadmc-1882f1be4849ab34aa289e0f74fd6ffadb31a7fa.tar.gz
Remove spin on unlock.
It doesn't seem to help, so let's just drop it.
Diffstat (limited to 'lib/thread')
-rw-r--r--lib/thread/mutex+linux.myr33
1 files changed, 5 insertions, 28 deletions
diff --git a/lib/thread/mutex+linux.myr b/lib/thread/mutex+linux.myr
index 61350b8..6b3818d 100644
--- a/lib/thread/mutex+linux.myr
+++ b/lib/thread/mutex+linux.myr
@@ -12,13 +12,14 @@ pkg thread =
const mtxlock : (mtx : mutex# -> void)
const mtxtrylock : (mtx : mutex# -> bool)
const mtxunlock : (mtx : mutex# -> void)
+
+ pkglocal const Unlocked = 0
+ pkglocal const Locked = 1
+ pkglocal const Contended = 2
;;
-const Unlocked = 0
-const Locked = 1
-const Contended = 2
generic Zptr = 0 castto(@a#)
-var nspin = 1 /* FIXME: pick a sane number, based on CPU count */
+var nspin = 10 /* FIXME: pick a sane number, based on CPU count */
const mkmtx = {
-> [._state = Unlocked]
@@ -35,7 +36,6 @@ const mtxlock = {mtx
if c == Unlocked
->
;;
- relax()
;;
/*
@@ -69,29 +69,6 @@ const mtxunlock = {mtx
->
;;
- /*
- Contended case: Now we unlock, and wait a little bit to see if anyone
- takes the lock. If someone takes the lock, we can avoid waking entering
- the kernel to wake processes. However, we need to set the lock to contended
- so that if there are still waiters, the thread that took the lock takes
- responsibility for unlocking.
- */
- for var i = 0; i < nspin; i++
- if mtx._state != Unlocked
- /*
- If we're locked, set the state to contended to avoid
- missed wakes.
- */
- if xcas(&mtx._state, Locked, Contended) == Contended
- ->
- ;;
- ;;
- relax()
- ;;
-
sys.futex(&mtx._state, sys.Futexwake | sys.Futexpriv, 1, Zptr, Zptr, 0)
}
-const relax = {
- /* FIXME: what is an appropriate way to kill CPU time without entering kernel? */
-}