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

1991/0821/gnot/lock.c (diff list | history)

gnot/lock.c on 1990/03091
1990/03091    
#include "u.h" 
#include "lib.h" 
#include "mem.h" 
#include "dat.h" 
#include "fns.h" 
1991/0606    
#include "errno.h" 
1990/03091    
 
1990/0617    
#define PCOFF -1 
1990/0403    
 
1990/03091    
void 
lock(Lock *l) 
{ 
	int i; 
 
1991/0821    
	for(i = 0; i < 1000000; i++){ 
1991/0723    
    		if (tas(&l->key) == 0){ 
1991/0820    
			if(u) 
1991/0614    
				u->p->hasspin = 1; 
1991/0723    
			l->pc = ((ulong*)&l)[PCOFF]; 
1990/03091    
			return; 
1990/0601    
		} 
1991/0821    
		if(u && u->p->state == Running) 
			sched(); 
1991/0723    
	} 
	i = l->key; 
	l->key = 0; 
 
	panic("lock loop 0x%lux key 0x%lux pc 0x%lux held by pc 0x%lux\n", l, i, 
		((ulong*)&l)[PCOFF], l->pc); 
1990/03091    
} 
 
int 
canlock(Lock *l) 
{ 
1991/0723    
	if(tas(&l->key)) 
		return 0; 
	l->pc = ((ulong*)&l)[PCOFF]; 
	if(u && u->p) 
		u->p->hasspin = 1; 
	return 1; 
1990/03091    
} 
 
void 
unlock(Lock *l) 
{ 
	l->pc = 0; 
1990/0403    
	l->key = 0; 
1991/0614    
	if(u && u->p) 
		u->p->hasspin = 0; 
1991/0606    
} 


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