changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / sys/src/ape/lib/ap/arm64/lock.c

changeset 7190: 41fb44a3b2dc
author: cinap_lenrek@felloff.net
date: Fri, 03 May 2019 21:06:46 +0200
permissions: -rw-r--r--
description: ape: initial support for arm64
1 #define _LOCK_EXTENSION
2 #include "../plan9/sys9.h"
3 #include <lock.h>
4 
5 extern int tas(int*);
6 extern unsigned long long _barrier(unsigned long long);
7 
8 void
9 lock(Lock *lk)
10 {
11  int i;
12 
13  /* once fast */
14  if(!tas(&lk->val))
15  return;
16  /* a thousand times pretty fast */
17  for(i=0; i<1000; i++){
18  if(!tas(&lk->val))
19  return;
20  _SLEEP(0);
21  }
22  /* now nice and slow */
23  for(i=0; i<1000; i++){
24  if(!tas(&lk->val))
25  return;
26  _SLEEP(100);
27  }
28  /* take your time */
29  while(tas(&lk->val))
30  _SLEEP(1000);
31 }
32 
33 int
34 canlock(Lock *lk)
35 {
36  return tas(&lk->val) == 0;
37 }
38 
39 void
40 unlock(Lock *lk)
41 {
42  lk->val = _barrier(0);
43 }