plan 9 kernel history: overview | file list | diff list

1990/0403/gnot/lock.c (diff list | history)

1990/0312/sys/src/9/gnot/lock.c:4,91990/0403/sys/src/9/gnot/lock.c:4,18 (short | long | prev | next)
1990/03091    
#include "dat.h" 
#include "fns.h" 
 
1990/0403    
#define PCOFF -2 
 
/* 
 *  N.B.  Ken's compiler generates a TAS instruction for the sequence: 
 * 
 *  	if(l->key >= 0){ 
 *		l->key |= 0x80; 
 *		... 
 */ 
1990/03091    
void 
lock(Lock *l) 
{ 
1990/0312/sys/src/9/gnot/lock.c:12,351990/0403/sys/src/9/gnot/lock.c:21,49
1990/03091    
	/* 
	 * Try the fast grab first 
	 */ 
    	if(tas(l->key) == 0){ 
		l->pc = ((ulong*)&l)[-1]; 
1990/0403    
    	if(l->key >= 0){ 
		l->key |= 0x80; 
		l->pc = ((ulong*)&i)[PCOFF]; 
1990/03091    
		return; 
	} 
	for(i=0; i<10000000; i++) 
    		if(tas(l->key) == 0){ 
			l->pc = ((ulong*)&l)[-1]; 
1990/0403    
    		if(l->key >= 0){ 
			l->key |= 0x80; 
			l->pc = ((ulong*)&i)[PCOFF]; 
1990/03091    
			return; 
	} 
	l->key[0] = 0; 
	panic("lock loop %lux pc %lux held by pc %lux\n", l, ((ulong*)&l)[-1], l->pc); 
1990/0403    
	l->key = 0; 
	panic("lock loop %lux pc %lux held by pc %lux\n", l, ((ulong*)&i)[PCOFF], l->pc); 
1990/03091    
} 
 
int 
canlock(Lock *l) 
{ 
	if(tas(l->key) == 0){ 
		l->pc = ((ulong*)&l)[-1]; 
1990/0403    
	int i; 
 
	if(l->key >= 0){ 
		l->key |= 0x80; 
		l->pc = ((ulong*)&i)[PCOFF]; 
1990/03091    
		return 1; 
	} 
	return 0; 
1990/0312/sys/src/9/gnot/lock.c:39,451990/0403/sys/src/9/gnot/lock.c:53,59
1990/03091    
unlock(Lock *l) 
{ 
	l->pc = 0; 
	l->key[0] = 0; 
1990/0403    
	l->key = 0; 
1990/03091    
} 
 
void 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)