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

1997/0220/port/taslock.c (diff list | history)

port/taslock.c on 1992/0222
1992/0222    
#include "u.h" 
1992/0321    
#include "../port/lib.h" 
1992/0222    
#include "mem.h" 
#include "dat.h" 
#include "fns.h" 
#include "../port/error.h" 
 
void 
1995/1030    
lockloop(Lock *l, ulong pc) 
{ 
	print("lock loop key 0x%lux pc 0x%lux held by pc 0x%lux proc %d\n", 
		l->key, pc, l->pc, l->pid); 
	dumpaproc(up); 
1996/0523    
 
	/* lower priority till we get the lock */ 
	if(up && up->state == Running && (getstatus()&IE)){ 
		up->lockpri = 1; 
		sched(); 
	} 
1995/1030    
} 
 
void 
1992/0222    
lock(Lock *l) 
{ 
1996/0523    
	int i; 
1996/0522    
	ulong pc, pid; 
1995/1009    
 
	pc = getcallerpc(l); 
1996/0523    
	pid = up ? up->pid : 0; 
1995/1009    
 
1996/0522    
	if(tas(&l->key) == 0){ 
		l->pc = pc; 
		l->pid = pid; 
1995/0110    
		return; 
1995/1009    
	} 
1995/0108    
 
1996/0522    
	for(;;){ 
		i = 0; 
		while(l->key) 
1996/0523    
			if(i++ > 100000000){ 
				i = 0; 
				lockloop(l, pc); 
1996/0522    
			} 
1995/1009    
		if(tas(&l->key) == 0){ 
			l->pc = pc; 
1996/0522    
			l->pid = pid; 
1996/0523    
			if(up) 
				up->lockpri = 0; 
1995/0108    
			return; 
1995/1009    
		} 
1995/0108    
	} 
1995/0110    
} 
1995/0108    
 
1995/0110    
void 
ilock(Lock *l) 
{ 
	ulong x; 
1995/1030    
	ulong pc, pid; 
1995/0110    
 
1995/1009    
	pc = getcallerpc(l); 
1995/1030    
	pid = up ? up->pid : 0; 
1995/1009    
 
1995/0110    
	x = splhi(); 
	if(tas(&l->key) == 0){ 
		l->sr = x; 
1995/1009    
		l->pc = pc; 
1995/1030    
		l->pid = pid; 
1993/1204    
		return; 
1995/0110    
	} 
 
1993/0830    
	for(;;){ 
1994/0808    
		while(l->key) 
			; 
1995/0110    
		if(tas(&l->key) == 0){ 
			l->sr = x; 
1995/1009    
			l->pc = pc; 
1995/1030    
			l->pid = pid; 
1992/0222    
			return; 
1995/0110    
		} 
1992/0222    
	} 
} 
 
1995/0109    
int 
canlock(Lock *l) 
1994/0322    
{ 
1996/0522    
	if(tas(&l->key)) 
1996/0511    
		return 0; 
1996/0522    
 
	l->pc = getcallerpc(l); 
1996/0523    
	l->pid = up ? up->pid : 0; 
1992/0222    
	return 1; 
} 
 
void 
unlock(Lock *l) 
{ 
1996/0511    
	l->key = 0; 
1996/0522    
	l->pc = 0; 
1997/0220    
	coherence(); 
1994/0322    
} 
 
void 
iunlock(Lock *l) 
{ 
	ulong sr; 
 
	sr = l->sr; 
1995/0110    
	l->key = 0; 
1995/1014    
	l->pc = 0; 
1994/0322    
	splx(sr); 
1997/0220    
	coherence(); 
1992/0222    
} 


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