summaryrefslogtreecommitdiff
path: root/src/thread/vmlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread/vmlock.c')
-rw-r--r--src/thread/vmlock.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/thread/vmlock.c b/src/thread/vmlock.c
index 125c6dc9..0a69b3e3 100644
--- a/src/thread/vmlock.c
+++ b/src/thread/vmlock.c
@@ -2,21 +2,20 @@
static volatile int vmlock[2];
-void __vm_lock(int inc)
+void __vm_wait()
{
- for (;;) {
- int v = vmlock[0];
- if (inc*v < 0) __wait(vmlock, vmlock+1, v, 1);
- else if (a_cas(vmlock, v, v+inc)==v) break;
- }
+ int tmp;
+ while ((tmp=vmlock[0]))
+ __wait(vmlock, vmlock+1, tmp, 1);
}
-void __vm_unlock(void)
+void __vm_lock(pthread_t self)
{
- int inc = vmlock[0]>0 ? -1 : 1;
- if (a_fetch_add(vmlock, inc)==-inc && vmlock[1])
- __wake(vmlock, -1, 1);
+ a_inc(vmlock);
}
-weak_alias(__vm_lock, __vm_lock_impl);
-weak_alias(__vm_unlock, __vm_unlock_impl);
+void __vm_unlock(pthread_t self)
+{
+ if (a_fetch_add(vmlock, -1)==1 && vmlock[1])
+ __wake(vmlock, -1, 1);
+}