Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/gnot/lock.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname gnot/lock.c 1990/03091
## diff -e /dev/null /n/bootesdump/1990/03091/sys/src/9/68020/lock.c
0a
#include "u.h"
#include "lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"

void
lock(Lock *l)
{
	int i;

	/*
	 * Try the fast grab first
	 */
    	if(tas(l->key) == 0){
		l->pc = ((ulong*)&l)[-1];
		return;
	}
	for(i=0; i<10000000; i++)
    		if(tas(l->key) == 0){
			l->pc = ((ulong*)&l)[-1];
			return;
	}
	l->key[0] = 0;
	panic("lock loop %lux pc %lux held by pc %lux\n", l, ((ulong*)&l)[-1], l->pc);
}

int
canlock(Lock *l)
{
	if(tas(l->key) == 0){
		l->pc = ((ulong*)&l)[-1];
		return 1;
	}
	return 0;
}

void
unlock(Lock *l)
{
	l->pc = 0;
	l->key[0] = 0;
}

void
qlock(QLock *q)
{
	Proc *p;

	if(canlock(&q->use))
		return;
	lock(&q->queue);
	if(canlock(&q->use)){
		unlock(&q->queue);
		return;
	}
	p = q->tail;
	if(p == 0)
		q->head = u->p;
	else
		p->qnext = u->p;
	q->tail = u->p;
	u->p->qnext = 0;
	u->p->state = Queueing;
	unlock(&q->queue);
	sched();
}

void
qunlock(QLock *q)
{
	Proc *p;

	lock(&q->queue);
	if(q->head){
		p = q->head;
		q->head = p->qnext;
		if(q->head == 0)
			q->tail = 0;
		unlock(&q->queue);
		ready(p);
	}else{
		unlock(&q->use);
		unlock(&q->queue);
	}
}
.
## diffname gnot/lock.c 1990/0312
## diff -e /n/bootesdump/1990/03091/sys/src/9/68020/lock.c /n/bootesdump/1990/0312/sys/src/9/68020/lock.c
68a
int
canqlock(QLock *q)
{
	return canlock(&q->use);
}

.
## diffname gnot/lock.c 1990/0403
## diff -e /n/bootesdump/1990/0312/sys/src/9/68020/lock.c /n/bootesdump/1990/0403/sys/src/9/68020/lock.c
42c
	l->key = 0;
.
31,32c
	int i;

	if(l->key >= 0){
		l->key |= 0x80;
		l->pc = ((ulong*)&i)[PCOFF];
.
24,25c
	l->key = 0;
	panic("lock loop %lux pc %lux held by pc %lux\n", l, ((ulong*)&i)[PCOFF], l->pc);
.
20,21c
    		if(l->key >= 0){
			l->key |= 0x80;
			l->pc = ((ulong*)&i)[PCOFF];
.
15,16c
    	if(l->key >= 0){
		l->key |= 0x80;
		l->pc = ((ulong*)&i)[PCOFF];
.
6a
#define PCOFF -2

/*
 *  N.B.  Ken's compiler generates a TAS instruction for the sequence:
 *
 *  	if(l->key >= 0){
 *		l->key |= 0x80;
 *		...
 */
.
## diffname gnot/lock.c 1990/05313
## diff -e /n/bootesdump/1990/0403/sys/src/9/68020/lock.c /n/bootesdump/1990/05313/sys/src/9/68020/lock.c
78a
	u->p->qlock = q;	/* DEBUG */
.
## diffname gnot/lock.c 1990/0601
## diff -e /n/bootesdump/1990/05313/sys/src/9/68020/lock.c /n/bootesdump/1990/0601/sys/src/9/68020/lock.c
34c
		}
.
14a
 *
 *	DO NOT TAKE THE ADDRESS OF l->key or the TAS will disappear.
.
## diffname gnot/lock.c 1990/0617
## diff -e /n/bootesdump/1990/0601/sys/src/9/68020/lock.c /n/bootesdump/1990/0617/sys/src/9/68020/lock.c
48c
		l->pc = ((ulong*)&l)[PCOFF];
.
44,45d
34c
			l->pc = ((ulong*)&l)[PCOFF];
.
28c
		l->pc = ((ulong*)&l)[PCOFF];
.
7c
#define PCOFF -1
.
## diffname gnot/lock.c 1990/0619
## diff -e /n/bootesdump/1990/0617/sys/src/9/68020/lock.c /n/bootesdump/1990/0619/sys/src/9/68020/lock.c
38c
dumpstack();
	panic("lock loop %lux pc %lux held by pc %lux\n", l, ((ulong*)&l)[PCOFF], l->pc);
.
## diffname gnot/lock.c 1990/0623
## diff -e /n/bootesdump/1990/0619/sys/src/9/68020/lock.c /n/bootesdump/1990/0623/sys/src/9/68020/lock.c
96a
	u->p->qlock = 0;
.
## diffname gnot/lock.c 1990/0705
## diff -e /n/bootesdump/1990/0623/sys/src/9/68020/lock.c /n/bootesdump/1990/0705/sys/src/9/68020/lock.c
45,47c
	Lock *ll = l;	/* do NOT take the address of l */
	if(ll->key >= 0){
		ll->key |= 0x80;
		ll->pc = ((ulong*)&l)[PCOFF];
.
37c
	ll->key = 0;
.
32,34c
    		if(ll->key >= 0){
			ll->key |= 0x80;
			ll->pc = ((ulong*)&l)[PCOFF];
.
26,28c
    	if(ll->key >= 0){
		ll->key |= 0x80;
		ll->pc = ((ulong*)&l)[PCOFF];
.
20a
	Lock *ll = l;	/* do NOT take the address of l */
.
## diffname gnot/lock.c 1990/1226
## diff -e /n/bootesdump/1990/0705/sys/src/9/68020/lock.c /n/bootesdump/1990/1226/sys/src/9/68020/lock.c
46c
	Lock *ll = l;	/* do NOT take the address of ll */
.
21c
	Lock *ll = l;	/* do NOT take the address of ll */
.
## diffname gnot/lock.c 1991/0109
## diff -e /n/bootesdump/1990/1226/sys/src/9/68020/lock.c /n/bootesdump/1991/0109/sys/src/9/68020/lock.c
39,40c
	print("lock loop %lux pc %lux held by pc %lux\n", l, ((ulong*)&l)[PCOFF], l->pc);
.
## diffname gnot/lock.c 1991/0311
## diff -e /n/bootesdump/1991/0201/sys/src/9/68020/lock.c /n/bootesdump/1991/0311/sys/src/9/gnot/lock.c
98c
	if(u)
		u->p->qlock = 0;
.
## diffname gnot/lock.c 1991/0428
## diff -e /n/bootesdump/1991/0311/sys/src/9/gnot/lock.c /n/bootesdump/1991/0428/sys/src/9/gnot/lock.c
60,111d
## diffname gnot/lock.c 1991/0606
## diff -e /n/bootesdump/1991/0428/sys/src/9/gnot/lock.c /n/bootesdump/1991/0606/sys/src/9/gnot/lock.c
58a
}

void
mklockseg(Seg *s)
{
	error(Esegaddr);
.
5a
#include "errno.h"
.
## diffname gnot/lock.c 1991/0608
## diff -e /n/bootesdump/1991/0606/sys/src/9/gnot/lock.c /n/bootesdump/1991/0608/sys/src/9/gnot/lock.c
66a

Page*
lkpage(Orig* o, ulong va)
{
}
.
## diffname gnot/lock.c 1991/0614
## diff -e /n/bootesdump/1991/0608/sys/src/9/gnot/lock.c /n/bootesdump/1991/0614/sys/src/9/gnot/lock.c
59a
	if(u && u->p)
		u->p->hasspin = 0;
.
49a
		if(u && u->p)
			u->p->hasspin = 1;
.
36a
			if(u && u->p)
				u->p->hasspin = 1;
.
30a
		if(u && u->p)
			u->p->hasspin = 1;
.
## diffname gnot/lock.c 1991/0705
## diff -e /n/bootesdump/1991/0614/sys/src/9/gnot/lock.c /n/bootesdump/1991/0705/sys/src/9/gnot/lock.c
69,79d
## diffname gnot/lock.c 1991/0723
## diff -e /n/bootesdump/1991/0705/sys/src/9/gnot/lock.c /n/bootesdump/1991/0723/sys/src/9/gnot/lock.c
50,58c
	if(tas(&l->key))
		return 0;
	l->pc = ((ulong*)&l)[PCOFF];
	if(u && u->p)
		u->p->hasspin = 1;
	return 1;
.
43,44c
	}
	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);
.
40a
			l->pc = ((ulong*)&l)[PCOFF];
.
35,38c
	for(i = 0; i < 1000; i++){
		sched();
    		if (tas(&l->key) == 0){
.
32a
		l->pc = ((ulong*)&l)[PCOFF];
.
28,30c
    	if(tas(&l->key) == 0){
.
22d
10,18d
## diffname gnot/lock.c 1991/0820
## diff -e /n/bootesdump/1991/0723/sys/src/9/gnot/lock.c /n/bootesdump/1991/0820/sys/src/9/gnot/lock.c
27c
			if(u)
.
24,25c
	for(i = 0; i < 100000; i++){
		if(u && u->p->state == Running)
			sched();
.
19c
		if(u)
.
## diffname gnot/lock.c 1991/0821
## diff -e /n/bootesdump/1991/0820/sys/src/9/gnot/lock.c /n/bootesdump/1991/0821/sys/src/9/gnot/lock.c
32a
		if(u && u->p->state == Running)
			sched();
.
15,26c
	for(i = 0; i < 1000000; i++){
.
## diffname gnot/lock.c 1992/0111
## diff -e /n/bootesdump/1991/0821/sys/src/9/gnot/lock.c /n/bootesdump/1992/0111/sys/src/9/gnot/lock.c
6c
#include "../port/error.h"
.
## diffname gnot/lock.c 1992/0222 # deleted
## diff -e /n/bootesdump/1992/0111/sys/src/9/gnot/lock.c /n/bootesdump/1992/0222/sys/src/9/gnot/lock.c
1,50d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.