File: lock.c

package info (click to toggle)
tra 20020816-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 1,696 kB
  • ctags: 2,623
  • sloc: ansic: 22,519; makefile: 406; asm: 269
file content (36 lines) | stat: -rw-r--r-- 341 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "os.h"

extern int _tas(void*);

int
canlock(Lock *l)
{
	return !_tas(&l->val);
}

void
unlock(Lock *l)
{
	l->val = 0;
}

void
lock(Lock *l)
{
	int i;

	for(i=0; i<10000; i++)
		if(canlock(l))
			return;
	for(i=0; i<1000; i++){
		if(canlock(l))
			return;
		usleep(1);
	}

	for(;;){
		if(canlock(l))
			return;
		usleep(1000);
	}
}