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