Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_posix/sys/src/ape/lib/ap/386/lock.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "../plan9/lib.h"
2
#include "../plan9/sys9.h"
3
#define _LOCK_EXTENSION
4
#include <lock.h>
5
//#include <lib9.h>
6
 
7
void
8
lock(Lock *l)
9
{
10
	if(ainc(&l->key) == 1)
11
		return;	/* changed from 0 -> 1: we hold lock */
12
	/* otherwise wait in kernel */
13
	while(_SEMACQUIRE(&l->sem, 1) < 0){
14
		/* interrupted; try again */
15
	}
16
}
17
 
18
void
19
unlock(Lock *l)
20
{
21
	if(adec(&l->key) == 0)
22
		return;	/* changed from 1 -> 0: no contention */
23
	_SEMRELEASE(&l->sem, 1);
24
}
25
 
26
int
27
canlock(Lock *l)
28
{
29
	if(ainc(&l->key) == 1)
30
		return 1;	/* changed from 0 -> 1: success */
31
	/* Undo increment (but don't miss wakeup) */
32
	if(adec(&l->key) == 0)
33
		return 0;	/* changed from 1 -> 0: no contention */
34
	_SEMRELEASE(&l->sem, 1);
35
	return 0;
36
}