File:  [Plan 9 NeXT] / lucent / sys / src / 9 / port / taslock.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 18:01:03 2018 UTC (8 years, 1 month ago) by root
Branches: lucent, MAIN
CVS tags: plan9, HEAD
Plan 9 NeXT

#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "../port/error.h"

void
lock(Lock *l)
{
	int i;
	ulong pc;

	pc = getcallerpc(((uchar*)&l) - sizeof(l));

	for(i = 0; i < 10000000; i++){
    		if (tas(&l->key) == 0){
			if(u)
				u->p->hasspin = 1;
			l->pc = pc;
			return;
		}
	}
	l->key = 0;
	panic("lock loop 0x%lux key 0x%lux pc 0x%lux held by pc 0x%lux\n",
			l->key, i, pc, l->pc);
}

void
ilock(Lock *l)
{
	int i;
	ulong pc;
	ulong x;

	pc = getcallerpc(((uchar*)&l) - sizeof(l));

	x = splhi();
	for(i = 0; i < 10000000; i++){
    		if (tas(&l->key) == 0){
			l->pc = pc;
			l->sr = x;
			return;
		}
	}
	l->key = 0;
	splx(x);
	panic("lock loop 0x%lux key 0x%lux pc 0x%lux held by pc 0x%lux\n",
			l->key, i, pc, l->pc);
}

int
canlock(Lock *l)
{
	if(tas(&l->key))
		return 0;
	l->pc = getcallerpc(((uchar*)&l) - sizeof(l));
	if(u && u->p)
		u->p->hasspin = 1;
	return 1;
}

void
unlock(Lock *l)
{
	l->pc = 0;
	l->key = 0;
	if(u && u->p)
		u->p->hasspin = 0;
}

void
iunlock(Lock *l)
{
	ulong sr;

	sr = l->sr;
	l->pc = 0;
	l->key = 0;
	splx(sr);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.