summaryrefslogtreecommitdiff
path: root/sys/src/libc/arm64/lock.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2019-05-03 20:57:30 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2019-05-03 20:57:30 +0200
commit9920ecc04b87cab3968f7f0c286b264bd31e132f (patch)
treee38cf67b782df089075d9c34269cc88d313fea2b /sys/src/libc/arm64/lock.c
parent59ff04ddb1b845bfd8542c886bb42c5cb3112a0b (diff)
libc: initial arm64 support
Diffstat (limited to 'sys/src/libc/arm64/lock.c')
-rw-r--r--sys/src/libc/arm64/lock.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/sys/src/libc/arm64/lock.c b/sys/src/libc/arm64/lock.c
new file mode 100644
index 000000000..307c4b7d6
--- /dev/null
+++ b/sys/src/libc/arm64/lock.c
@@ -0,0 +1,41 @@
+#include <u.h>
+#include <libc.h>
+
+extern uintptr _barrier(uintptr);
+
+void
+lock(Lock *lk)
+{
+ int i;
+
+ /* once fast */
+ if(!_tas(&lk->val))
+ return;
+ /* a thousand times pretty fast */
+ for(i=0; i<1000; i++){
+ if(!_tas(&lk->val))
+ return;
+ sleep(0);
+ }
+ /* now nice and slow */
+ for(i=0; i<1000; i++){
+ if(!_tas(&lk->val))
+ return;
+ sleep(100);
+ }
+ /* take your time */
+ while(_tas(&lk->val))
+ sleep(1000);
+}
+
+int
+canlock(Lock *lk)
+{
+ return _tas(&lk->val) == 0;
+}
+
+void
+unlock(Lock *lk)
+{
+ lk->val = _barrier(0);
+}