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

1995/0108/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 
lock(Lock *l) 
{ 
1995/0108    
	int n; 
 
	if(up) { 
		n = up->inlock+2; 
		up->inlock = n; 
		if(tas(&l->key) == 0) 
			return; 
 
		for(;;){ 
			while(l->key) 
				if(conf.nproc == 1) { 
					up->yield = 1; 
					sched(); 
				} 
			up->inlock = n; 
			if(tas(&l->key) == 0) 
				return; 
		} 
	} 
 
1993/1204    
	if(tas(&l->key) == 0) 
		return; 
1993/0830    
	for(;;){ 
1994/0808    
		while(l->key) 
			; 
1993/0830    
		if(tas(&l->key) == 0) 
1992/0222    
			return; 
	} 
} 
 
1994/0322    
void 
ilock(Lock *l) 
{ 
1994/0323    
	ulong x; 
 
	x = splhi(); 
	if(tas(&l->key) == 0){ 
		l->sr = x; 
1994/0322    
		return; 
1994/0323    
	} 
1994/0525    
 
1994/0322    
	for(;;){ 
		while(l->key) 
			; 
1994/0323    
		if(tas(&l->key) == 0){ 
			l->sr = x; 
1994/0322    
			return; 
1994/0323    
		} 
1994/0322    
	} 
} 
 
1992/0222    
int 
canlock(Lock *l) 
{ 
	if(tas(&l->key)) 
		return 0; 
1994/0322    
 
1992/0222    
	return 1; 
} 
 
void 
unlock(Lock *l) 
{ 
1995/0108    
	int n; 
 
1992/0222    
	l->key = 0; 
1995/0108    
	if(up) { 
		n = up->inlock-2; 
		if(n < 0) 
			n = 0; 
		up->inlock = n; 
	} 
1994/0322    
} 
 
void 
iunlock(Lock *l) 
{ 
	ulong sr; 
 
	sr = l->sr; 
	l->key = 0; 
	splx(sr); 
1992/0222    
} 


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