]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libc/arm64/lock.c
libc: use MOVP instruction for arm64 memmove() and memset()
[plan9front.git] / sys / src / libc / arm64 / lock.c
1 #include <u.h>
2 #include <libc.h>
3
4 extern uintptr _barrier(uintptr);
5
6 void
7 lock(Lock *lk)
8 {
9         int i;
10
11         /* once fast */
12         if(!_tas(&lk->val))
13                 return;
14         /* a thousand times pretty fast */
15         for(i=0; i<1000; i++){
16                 if(!_tas(&lk->val))
17                         return;
18                 sleep(0);
19         }
20         /* now nice and slow */
21         for(i=0; i<1000; i++){
22                 if(!_tas(&lk->val))
23                         return;
24                 sleep(100);
25         }
26         /* take your time */
27         while(_tas(&lk->val))
28                 sleep(1000);
29 }
30
31 int
32 canlock(Lock *lk)
33 {
34         return _tas(&lk->val) == 0;
35 }
36
37 void
38 unlock(Lock *lk)
39 {
40         lk->val = _barrier(0);
41 }