diff options
author | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-09-21 19:53:27 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@gmx.de> | 2013-09-21 19:53:27 +0200 |
commit | 3d05e77ca1f743e5b4091c6bfe311460175ed9ae (patch) | |
tree | d17a262c559e389e3adb6171de308800eb9d3426 /sys/src/libc/alpha | |
parent | 041e4852d258f05fe5f60964a76c99714905774e (diff) |
libc: change tas/sleep locks to cas/semacquire/semrelease locks (from sources)
spinlocks have been changed to use the new semacquire/semrelease
syscalls in combination with atomic compare and swap operations.
Diffstat (limited to 'sys/src/libc/alpha')
-rw-r--r-- | sys/src/libc/alpha/cycles.c | 7 | ||||
-rw-r--r-- | sys/src/libc/alpha/lock.c | 41 | ||||
-rw-r--r-- | sys/src/libc/alpha/mkfile | 2 |
3 files changed, 42 insertions, 8 deletions
diff --git a/sys/src/libc/alpha/cycles.c b/sys/src/libc/alpha/cycles.c deleted file mode 100644 index 9bad3a989..000000000 --- a/sys/src/libc/alpha/cycles.c +++ /dev/null @@ -1,7 +0,0 @@ -#include <u.h> -#include <libc.h> - -void cycles(uvlong*u) -{ - *u = 0LL; -} diff --git a/sys/src/libc/alpha/lock.c b/sys/src/libc/alpha/lock.c new file mode 100644 index 000000000..c0966fcac --- /dev/null +++ b/sys/src/libc/alpha/lock.c @@ -0,0 +1,41 @@ +#include <u.h> +#include <libc.h> + +void +lock(Lock *lk) +{ + int i; + + /* once fast */ + if(!_tas((int*)&lk->key)) + return; + /* a thousand times pretty fast */ + for(i=0; i<1000; i++){ + if(!_tas((int*)&lk->key)) + return; + sleep(0); + } + /* now nice and slow */ + for(i=0; i<1000; i++){ + if(!_tas((int*)&lk->key)) + return; + sleep(100); + } + /* take your time */ + while(_tas((int*)&lk->key)) + sleep(1000); +} + +int +canlock(Lock *lk) +{ + if(_tas((int*)&lk->key)) + return 0; + return 1; +} + +void +unlock(Lock *lk) +{ + lk->key = 0; +} diff --git a/sys/src/libc/alpha/mkfile b/sys/src/libc/alpha/mkfile index ef66ac423..299a97c97 100644 --- a/sys/src/libc/alpha/mkfile +++ b/sys/src/libc/alpha/mkfile @@ -18,7 +18,7 @@ SFILES=\ CFILES=\ _seek.c\ - cycles.c\ + lock.c\ notejmp.c\ HFILES=/sys/include/libc.h |