Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/port/qlock.c

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


## diffname port/qlock.c 1991/0428
## diff -e /dev/null /n/bootesdump/1991/0428/sys/src/9/port/qlock.c
0a
#include "u.h"
#include "lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"


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;
/*	u->p->qlock = q;	/* DEBUG */
	unlock(&q->queue);
	sched();
}

int
canqlock(QLock *q)
{
	return canlock(&q->use);
}

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

	lock(&q->queue);
/*	u->p->qlock = 0; /* DEBUG */
	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 port/qlock.c 1991/0614
## diff -e /n/bootesdump/1991/0428/sys/src/9/port/qlock.c /n/bootesdump/1991/0614/sys/src/9/port/qlock.c
14a
	}
.
13c
	if(canlock(&q->use)){
		if(u)
			u->p->hasspin = 0;
.
## diffname port/qlock.c 1991/0705
## diff -e /n/bootesdump/1991/0614/sys/src/9/port/qlock.c /n/bootesdump/1991/0705/sys/src/9/port/qlock.c
17d
13,15c
	if(canlock(&q->use))
.
## diffname port/qlock.c 1991/0711
## diff -e /n/bootesdump/1991/0705/sys/src/9/port/qlock.c /n/bootesdump/1991/0711/sys/src/9/port/qlock.c
19a
	if(u == 0)
		panic("qlock");
.
## diffname port/qlock.c 1991/0726
## diff -e /n/bootesdump/1991/0711/sys/src/9/port/qlock.c /n/bootesdump/1991/0726/sys/src/9/port/qlock.c
57a
		splx(s);
.
55a
		/* horrible botch because clock does a canqlock */
		int s = splhi();
.
## diffname port/qlock.c 1991/0727
## diff -e /n/bootesdump/1991/0726/sys/src/9/port/qlock.c /n/bootesdump/1991/0727/sys/src/9/port/qlock.c
60d
56,57d
## diffname port/qlock.c 1991/1002
## diff -e /n/bootesdump/1991/0727/sys/src/9/port/qlock.c /n/bootesdump/1991/1002/sys/src/9/port/qlock.c
58a
	q->locked = 0;
	unlock(&q->use);
.
57c
		ready(p);
		return;
.
53,55d
46,49c
	lock(&q->use);
	p = q->head;
	if(p) {
.
38c
	lock(&q->use);
	if(q->locked) {
		unlock(&q->use);
		return 0;
	}
	q->locked = 1;
	unlock(&q->use);
	return 1;
.
26,31c
		p->qnext = mp;
	q->tail = mp;
	mp->qnext = 0;
	mp->state = Queueing;
	unlock(&q->use);
.
24c
		q->head = mp;
.
22a
	mp = u->p;
.
20,21d
15,18d
13c
	lock(&q->use);
	if(!q->locked) {
		q->locked = 1;
		unlock(&q->use);
.
11c
	Proc *p, *mp;
.
## diffname port/qlock.c 1991/1011
## diff -e /n/bootesdump/1991/1002/sys/src/9/port/qlock.c /n/bootesdump/1991/1011/sys/src/9/port/qlock.c
62a

void
rlock(RWlock *l)
{
	qlock(&l->x);		/* wait here for writers and exclusion */
	lock(l);
	l->readers++;
	canqlock(&l->k);	/* block writers if we are the first reader */
	unlock(l);
	qunlock(&l->x);
}

void
runlock(RWlock *l)
{
	lock(l);
	if(--l->readers == 0)	/* last reader out allows writers */
		qunlock(&l->k);
	unlock(l);
}

void
wlock(RWlock *l)
{
	qlock(&l->x);		/* wait here for writers and exclusion */
	qlock(&l->k);		/* wait here for last reader */
}

void
wunlock(RWlock *l)
{
	qunlock(&l->x);
	qunlock(&l->k);
}
.
## diffname port/qlock.c 1991/1030
## diff -e /n/bootesdump/1991/1011/sys/src/9/port/qlock.c /n/bootesdump/1991/1030/sys/src/9/port/qlock.c
36c
	if(q->locked){
.
## diffname port/qlock.c 1992/0321
## diff -e /n/bootesdump/1991/1030/sys/src/9/port/qlock.c /n/bootesdump/1992/0321/sys/src/9/port/qlock.c
2c
#include "../port/lib.h"
.
## diffname port/qlock.c 1992/0509
## diff -e /n/bootesdump/1992/0321/sys/src/9/port/qlock.c /n/bootesdump/1992/0509/sys/src/9/port/qlock.c
12a
	if(u)
		u->p->qlockpc = getcallerpc(((uchar*)&q) - sizeof(q));
.
## diffname port/qlock.c 1992/0912
## diff -e /n/bootesdump/1992/0509/sys/src/9/port/qlock.c /n/bootesdump/1992/0912/sys/src/9/port/qlock.c
51a
	if(u)
		u->p->qlockpc = 0;
.
41a
	if(u)
		u->p->qlockpc = getcallerpc(((uchar*)&q) - sizeof(q));
.
## diffname port/qlock.c 1993/0501
## diff -e /n/bootesdump/1992/0912/sys/src/9/port/qlock.c /n/fornaxdump/1993/0501/sys/src/brazil/port/qlock.c
54,55d
42,43d
22c
	mp = up;
.
13,14d
## diffname port/qlock.c 1993/0522
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/port/qlock.c /n/fornaxdump/1993/0522/sys/src/brazil/port/qlock.c
35c
	if(!canlock(&q->use))
		return 0;
.
## diffname port/qlock.c 1994/0322
## diff -e /n/fornaxdump/1993/0522/sys/src/brazil/port/qlock.c /n/fornaxdump/1994/0322/sys/src/brazil/port/qlock.c
49a

if(up==0) { iprint("QUNLOCK at ilevel PC=%lux\n", getcallerpc(0)); for(;;); }
.
12a
if(up==0) { iprint("QLOCK at ilevel PC=%lux\n", getcallerpc(0)); for(;;); }

.
## diffname port/qlock.c 1994/0325
## diff -e /n/fornaxdump/1994/0322/sys/src/brazil/port/qlock.c /n/fornaxdump/1994/0325/sys/src/brazil/port/qlock.c
36a
up->qpc =  getcallerpc(0);
.
13c
up->qpc =  getcallerpc(0);
.
## diffname port/qlock.c 1994/0331
## diff -e /n/fornaxdump/1994/0325/sys/src/brazil/port/qlock.c /n/fornaxdump/1994/0331/sys/src/brazil/port/qlock.c
53,54d
37d
13,14d
## diffname port/qlock.c 1995/0104
## diff -e /n/fornaxdump/1994/0331/sys/src/brazil/port/qlock.c /n/fornaxdump/1995/0104/sys/src/brazil/port/qlock.c
50a
	if((getstatus()&IE)==0)
		print("qunlock hi %lux\n", getcallerpc(q));
.
12a
	if((getstatus()&IE)==0)
		print("qlock hi %lux\n", getcallerpc(q));
.
## diffname port/qlock.c 1995/0126
## diff -e /n/fornaxdump/1995/0104/sys/src/brazil/port/qlock.c /n/fornaxdump/1995/0126/sys/src/brazil/port/qlock.c
53,54d
13,14d
## diffname port/qlock.c 1995/1017
## diff -e /n/fornaxdump/1995/0126/sys/src/brazil/port/qlock.c /n/fornaxdump/1995/1017/sys/src/brazil/port/qlock.c
96a
	qunlock(&l->x);
.
95d
## diffname port/qlock.c 1997/0414
## diff -e /n/fornaxdump/1995/1017/sys/src/brazil/port/qlock.c /n/emeliedump/1997/0414/sys/src/brazil/port/qlock.c
7d
## diffname port/qlock.c 1998/0325
## diff -e /n/emeliedump/1997/0414/sys/src/brazil/port/qlock.c /n/emeliedump/1998/0325/sys/src/brazil/port/qlock.c
94,95c
	Proc *p;

	lock(&q->use);
	p = q->head;
	if(p == nil){
		q->writer = 0;
		unlock(&q->use);
		return;
	}

	if(p->state == QueueingW){
		/* start waiting writer */
		q->head = p->qnext;
		if(q->head == nil)
			q->tail = nil;
		unlock(&q->use);
		ready(p);
		return;
	}

	if(p->state != Queueing)
		panic("wunlock");

	/* waken waiting readers */
	while(q->head != nil && q->head->state == Queueing){
		p = q->head;
		q->head = p->qnext;
		q->readers++;
		ready(p);
	}
	if(q->head == nil)
		q->tail = nil;
	q->writer = 0;
	unlock(&q->use);
.
92c
wunlock(RWlock *q)
.
87,88c
	Proc *p, *mp;

	lock(&q->use);
rwstats.wlock++;
	if(q->readers == 0 && q->writer == 0){
		/* noone waiting, go for it */
		q->writer = 1;
		unlock(&q->use);
		return;
	}

	/* wait */
rwstats.wlockq++;
	p = q->tail;
	mp = up;
	if(p == nil)
		q->head = mp;
	else
		p->qnext = mp;
	q->tail = mp;
	mp->qnext = 0;
	mp->state = QueueingW;
	unlock(&q->use);
	sched();
.
85c
wlock(RWlock *q)
.
78,81c
	Proc *p;

	lock(&q->use);
	p = q->head;
	if(--(q->readers) > 0 || p == nil){
		unlock(&q->use);
		return;
	}

	/* start waiting writer */
	if(p->state != QueueingW)
		panic("runlock");
	q->head = p->qnext;
	if(q->head == 0)
		q->tail = 0;
	q->writer = 1;
	unlock(&q->use);
	ready(p);
.
76c
runlock(RWlock *q)
.
67,72c
	Proc *p, *mp;

	lock(&q->use);
rwstats.rlock++;
	if(q->writer == 0 && q->head == nil){
		/* no writer, go for it */
		q->readers++;
		unlock(&q->use);
		return;
	}

rwstats.rlockq++;
	p = q->tail;
	mp = up;
	if(p == 0)
		q->head = mp;
	else
		p->qnext = mp;
	q->tail = mp;
	mp->qnext = 0;
	mp->state = Queueing;
	unlock(&q->use);
	sched();
.
65c
rlock(RWlock *q)
.
17a
rwstats.qlockq++;
.
12a
rwstats.qlock++;
.
6a
struct {
	ulong rlock;
	ulong rlockq;
	ulong wlock;
	ulong wlockq;
	ulong qlock;
	ulong qlockq;
} rwstats;

.
## diffname port/qlock.c 1998/0805
## diff -e /n/emeliedump/1998/0325/sys/src/brazil/port/qlock.c /n/emeliedump/1998/0805/sys/src/brazil/port/qlock.c
182a
//{int i;
//for(i=0;i<nelem(q->pidr); i++)
//if(q->pidr[i]==0) {
//q->pidr[i] = p->pid;
//break;
//}}
.
168a
//q->pidw = p->pid;
.
167d
160a
//if(q->pidw!=up->pid)
//print("not qw\n");
//q->pidw = 0;
.
150a
//print("%d wl for %d%d", up->pid, q->readers, q->writer);
//if(q->pidw) print(" w%d", q->pidw);
//{int i;
//for(i=0; i<nelem(q->pidr); i++)
//if(q->pidr[i])
//print(" %d", q->pidr[i]);
//print("\n");
//}
.
141c
//rwstats.wlockq++;
.
134a
//q->pidw = up->pid;
.
121a
//q->pidw = p->pid;
.
108a
//{int i;
//for(i=0; i<nelem(q->pidr); i++)
//if(q->pidr[i]==up->pid) {
//q->pidr[i] = 0;
//break;
//}}
.
98a
//print("%d rl for w%d\n", up->pid, q->pidw);
.
83a
//{int i;
//for(i=0; i<nelem(q->pidr); i++)
//if(q->pidr[i]==0) {
//q->pidr[i]=up->pid;
//break;
//}}
.
80a
//{int i;
//for(i=0; i<nelem(q->pidr); i++)
//if(q->pidr[i]==up->pid)
//print("***already %d\n", up->pid);
//}
.
## diffname port/qlock.c 1998/0806
## diff -e /n/emeliedump/1998/0805/sys/src/brazil/port/qlock.c /n/emeliedump/1998/0806/sys/src/brazil/port/qlock.c
213,219c
	while(q->head != nil && q->head->state == QueueingR){
.
209c
	if(p->state != QueueingR)
.
199d
189,191d
171,178d
161c
rwstats.wlockq++;
.
154d
140d
121,126d
109,110c
	mp->state = QueueingR;
.
89,94d
81,85d
## diffname port/qlock.c 1999/0110
## diff -e /n/emeliedump/1998/0806/sys/src/brazil/port/qlock.c /n/emeliedump/1999/0110/sys/src/brazil/port/qlock.c
37a
	up->qpc = getcallerpc(q);
.
## diffname port/qlock.c 1999/0124
## diff -e /n/emeliedump/1999/0110/sys/src/brazil/port/qlock.c /n/emeliedump/1999/0124/sys/src/brazil/port/qlock.c
144a
	if(mp == nil)
		panic("wlock");
.
92a
	if(mp == nil)
		panic("rlock");
.
30a
	if(mp == nil)
		panic("qlock");
.
## diffname port/qlock.c 1999/0302
## diff -e /n/emeliedump/1999/0124/sys/src/brazil/port/qlock.c /n/emeliedump/1999/0302/sys/src/brazil/port/qlock.c
198a

/* same as rlock but punts if there are any readers waiting */
int
canrlock(RWlock *q)
{
	lock(&q->use);
rwstats.rlock++;
	if(q->writer == 0 && q->head == nil){
		/* no writer, go for it */
		q->readers++;
		unlock(&q->use);
		return 1;
	}
	unlock(&q->use);
	return 0;
}
.
## diffname port/qlock.c 1999/0501
## diff -e /n/emeliedump/1999/0302/sys/src/brazil/port/qlock.c /n/emeliedump/1999/0501/sys/src/brazil/port/qlock.c
40c
	up->qpc = getcallerpc(&q);
.
## diffname port/qlock.c 2000/0107
## diff -e /n/emeliedump/1999/0501/sys/src/brazil/port/qlock.c /n/emeliedump/2000/0107/sys/src/9/port/qlock.c
139a
		q->wpc = getcallerpc(&q);
		q->wproc = up;
.
## diffname port/qlock.c 2002/0315
## diff -e /n/emeliedump/2000/0107/sys/src/9/port/qlock.c /n/emeliedump/2002/0315/sys/src/9/port/qlock.c
159a
	if (isedf(mp))
		edf_block(mp);
.
103a
	if (isedf(mp))
		edf_block(mp);
.
39a
	if (isedf(mp))
		edf_block(mp);
.
5a
#include "../port/edf.h"
.
## diffname port/qlock.c 2002/0320
## diff -e /n/emeliedump/2002/0315/sys/src/9/port/qlock.c /n/emeliedump/2002/0320/sys/src/9/port/qlock.c
167d
164a
	unlock(&q->use);
.
109d
106a
	unlock(&q->use);
.
44a
	if (isedf(mp))
		edf_block(mp);
.
41,42d
## diffname port/qlock.c 2002/0402
## diff -e /n/emeliedump/2002/0320/sys/src/9/port/qlock.c /n/emeliedump/2002/0402/sys/src/9/port/qlock.c
166,167d
108,109d
43,44d
6d
## diffname port/qlock.c 2002/0403
## diff -e /n/emeliedump/2002/0402/sys/src/9/port/qlock.c /n/emeliedump/2002/0403/sys/src/9/port/qlock.c
207c
	rwstats.rlock++;
.
148c
	rwstats.wlockq++;
.
137c
	rwstats.wlock++;
.
92c
	rwstats.rlockq++;
.
84c
	rwstats.rlock++;
.
28c
	rwstats.qlockq++;
.
22c
	rwstats.qlock++;
.
## diffname port/qlock.c 2002/0404
## diff -e /n/emeliedump/2002/0403/sys/src/9/port/qlock.c /n/emeliedump/2002/0404/sys/src/9/port/qlock.c
160a
	if (isedf(mp))
		edf_block(mp);
.
104a
	if (isedf(mp))
		edf_block(mp);
.
41a
	if (isedf(mp))
		edf_block(mp);
.
5a
#include "../port/edf.h"
.
## diffname port/qlock.c 2002/0410
## diff -e /n/emeliedump/2002/0404/sys/src/9/port/qlock.c /n/emeliedump/2002/0410/sys/src/9/port/qlock.c
167c
		edfblock(mp);
.
109c
		edfblock(mp);
.
44c
		edfblock(mp);
.
6d
## diffname port/qlock.c 2002/0420
## diff -e /n/emeliedump/2002/0410/sys/src/9/port/qlock.c /n/emeliedump/2002/0420/sys/src/9/port/qlock.c
42,43c
	if (isedf(up))
		edfblock(up);
.
36,39c
		p->qnext = up;
	q->tail = up;
	up->qnext = 0;
	up->state = Queueing;
.
34c
		q->head = up;
.
30,32d
20a
	if(up == 0)
		panic("qlock");
	if(m->ilockdepth != 0 && !shutup){
		print("qlock: %lux: ilockdepth %d", getcallerpc(&q), m->ilockdepth);
		shutup = 1;
	}
	if(up->nlocks && !shutup){
		print("qlock: %lux: nlocks %d", getcallerpc(&q), up->nlocks);
		shutup = 1;
	}

.
19c
	Proc *p;
.
15a
int shutup=1;	/* RSC: you can take this out, it's just to silence a print in a loop on the dist floppy */
.
## diffname port/qlock.c 2002/0421
## diff -e /n/emeliedump/2002/0420/sys/src/9/port/qlock.c /n/emeliedump/2002/0421/sys/src/9/port/qlock.c
217c
/* same as rlock but punts if there are any writers waiting */
.
77c
	if(p){
.
51c
	if(isedf(up))
.
26,31c
	if(up->nlocks)
		print("qlock: %lux: nlocks %lud", getcallerpc(&q), up->nlocks);
.
24c
	if(m->ilockdepth != 0)
.
16d
## diffname port/qlock.c 2002/0423
## diff -e /n/emeliedump/2002/0421/sys/src/9/port/qlock.c /n/emeliedump/2002/0423/sys/src/9/port/qlock.c
169,170c
	if (isedf(up))
		edfblock(up);
.
164,167c
		p->qnext = up;
	q->tail = up;
	up->qnext = 0;
	up->state = QueueingW;
.
162c
		q->head = up;
.
158,159c
	if(up == nil)
.
142c
	Proc *p;
.
111,112c
	if (isedf(up))
		edfblock(up);
.
106,109c
		p->qnext = up;
	q->tail = up;
	up->qnext = 0;
	up->state = QueueingR;
.
104c
		q->head = up;
.
100,101c
	if(up == nil)
.
87c
	Proc *p;
.
## diffname port/qlock.c 2002/0427
## diff -e /n/emeliedump/2002/0423/sys/src/9/port/qlock.c /n/emeliedump/2002/0427/sys/src/9/port/qlock.c
34a
	if(up == 0)
		panic("qlock");
.
25c
	if(up != nil && up->nlocks)
.
21,22d
## diffname port/qlock.c 2002/0704
## diff -e /n/emeliedump/2002/0427/sys/src/9/port/qlock.c /n/emeliedump/2002/0704/sys/src/9/port/qlock.c
167,168c
	if (edf->isedf(up))
		edf->edfblock(up);
.
110,111c
	if (edf->isedf(up))
		edf->edfblock(up);
.
46,47c
	if(edf->isedf(up))
		edf->edfblock(up);
.
## diffname port/qlock.c 2003/0405
## diff -e /n/emeliedump/2002/0704/sys/src/9/port/qlock.c /n/emeliedump/2003/0405/sys/src/9/port/qlock.c
25a
	if(q->use.key == 0x55555555)
		panic("qlock: q %p, key 5*\n", q);
.
## diffname port/qlock.c 2003/0406
## diff -e /n/emeliedump/2003/0405/sys/src/9/port/qlock.c /n/emeliedump/2003/0406/sys/src/9/port/qlock.c
169c
	if(edf->isedf(up))
.
112c
	if(edf->isedf(up))
.

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].