summaryrefslogtreecommitdiff
path: root/sys/src/libc/sparc
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-09-21 19:53:27 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2013-09-21 19:53:27 +0200
commit3d05e77ca1f743e5b4091c6bfe311460175ed9ae (patch)
treed17a262c559e389e3adb6171de308800eb9d3426 /sys/src/libc/sparc
parent041e4852d258f05fe5f60964a76c99714905774e (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/sparc')
-rw-r--r--sys/src/libc/sparc/lock.c41
-rw-r--r--sys/src/libc/sparc/mkfile2
2 files changed, 42 insertions, 1 deletions
diff --git a/sys/src/libc/sparc/lock.c b/sys/src/libc/sparc/lock.c
new file mode 100644
index 000000000..c0966fcac
--- /dev/null
+++ b/sys/src/libc/sparc/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/sparc/mkfile b/sys/src/libc/sparc/mkfile
index af2b18944..6ef2cf55c 100644
--- a/sys/src/libc/sparc/mkfile
+++ b/sys/src/libc/sparc/mkfile
@@ -22,7 +22,7 @@ SFILES=\
vlop.s
CFILES=\
- cycles.c\
+ lock.c\
notejmp.c\
sqrt.c\
vlrt.c\