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

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


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

#include	"ureg.h"

Alarm	*alarmtab;

Alarm*
alarm(int ms, void (*f)(Alarm*), void *arg)
{
	Alarm *a, *w, *pw;
	ulong s;
	if(ms < 0)
		ms = 0;
	a = newalarm();
	a->dt = ms/MS2HZ;
	a->f = f;
	a->arg = arg;
	s = splhi();
	lock(&m->alarmlock);
	pw = 0;
	for(w=m->alarm; w; pw=w, w=w->next){
		if(w->dt <= a->dt){
			a->dt -= w->dt;
			continue;
		}
		w->dt -= a->dt;
		break;
	}
	insert(&m->alarm, pw, a);
	unlock(&m->alarmlock);
	splx(s);
	return a;
}

void
cancel(Alarm *a)
{
	a->f = 0;
}

Alarm*
newalarm(void)
{
	int i;
	Alarm *a;

	for(i=0,a=alarmtab; i<conf.nalarm; i++,a++)
		if(a->busy==0 && a->f==0 && canlock(a)){
			if(a->busy){
				unlock(a);
				continue;
			}
			a->f = 0;
			a->arg = 0;
			a->busy = 1;
			unlock(a);
			return a;
		}
	panic("newalarm");
}

void
alarminit(void)
{
	int i;

	alarmtab = ialloc(conf.nalarm*sizeof(Alarm), 0);
	for(i=0; i<conf.nalarm; i++){
		lock(&alarmtab[i]);	/* allocate locks, as they are used at interrupt time */
		unlock(&alarmtab[i]);
	}
}

void
delay(int ms)
{
	ulong t, *p;
	int i;

	ms *= 1000;	/* experimentally determined */
	for(i=0; i<ms; i++)
		;
}

void
clock(Ureg *ur)
{
	int i;
	Alarm *a;
	void (*f)(void*);
	Proc *p;

	SYNCREG[1] = 0x5F;	/* clear interrupt */
	m->ticks++;
	p = m->proc;
	if(p)
		p->time[p->insyscall]++;
	if(canlock(&m->alarmlock)){
		if(m->alarm){
			a = m->alarm;
			a->dt--;
			while(a && a->dt<=0){
				f = a->f;	/* avoid race with cancel */
				if(f)
					(*f)(a);
				delete(&m->alarm, 0, a);
				a->busy = 0;
				a = m->alarm;
			}
		}
		unlock(&m->alarmlock);
	}
	if((ur->sr&SPL(7)) == 0){
		spllo();
		if(p && p->state==Running)
			sched();
	}
}
.
## diffname gnot/clock.c 1990/0312
## diff -e /n/bootesdump/1990/03091/sys/src/9/68020/clock.c /n/bootesdump/1990/0312/sys/src/9/68020/clock.c
102a
	}
.
101c
	if(p){
		p->pc = ur->pc;
.
## diffname gnot/clock.c 1990/0321
## diff -e /n/bootesdump/1990/0312/sys/src/9/68020/clock.c /n/bootesdump/1990/0321/sys/src/9/68020/clock.c
123c
			checksched();
.
119a
	kbdclock();
.
## diffname gnot/clock.c 1990/0504
## diff -e /n/bootesdump/1990/0321/sys/src/9/68020/clock.c /n/bootesdump/1990/0504/sys/src/9/68020/clock.c
120a
	mouseclock();
.
## diffname gnot/clock.c 1990/06111
## diff -e /n/bootesdump/1990/0504/sys/src/9/68020/clock.c /n/bootesdump/1990/06111/sys/src/9/68020/clock.c
20c
	a->dt = MS2TK(ms);
.
## diffname gnot/clock.c 1990/0703
## diff -e /n/bootesdump/1990/06111/sys/src/9/68020/clock.c /n/bootesdump/1990/0703/sys/src/9/68020/clock.c
125a
			if(u->nnote && (ur->sr&SUPER)==0)
				notify(ur);
		}
.
124c
		if(p && p->state==Running){
.
## diffname gnot/clock.c 1990/0728
## diff -e /n/bootesdump/1990/0703/sys/src/9/68020/clock.c /n/bootesdump/1990/0728/sys/src/9/68020/clock.c
117,118c
			unlock(&m->alarmlock);

			/*  execute alarm functions outside the lock */
			for(i = 0; i < n; i++){
				f = alist[i]->f;	/* avoid race with cancel */
				if(f)
					(*f)(alist[i]);
				alist[i]->busy = 0;
			}
		} else
			unlock(&m->alarmlock);
.
114d
109,112c
			for(n = 0; a && a->dt<=0 && n<NA; n++){
				alist[n] = a;
.
96a
	Alarm *alist[NA];
.
93c
	int i, n;
.
89a
#define NA 10
.
## diffname gnot/clock.c 1990/1004
## diff -e /n/bootesdump/1990/0728/sys/src/9/68020/clock.c /n/bootesdump/1990/1004/sys/src/9/68020/clock.c
130,136c
	if((ur->sr&SPL(7)) == 0 && p && p->state==Running){
		sched();
		if(u->nnote && (ur->sr&SUPER)==0)
			notify(ur);
.
105c
		if (p->state==Running)
			p->time[p->insyscall]++;
.
## diffname gnot/clock.c 1990/1012
## diff -e /n/bootesdump/1990/1004/sys/src/9/68020/clock.c /n/bootesdump/1990/1012/sys/src/9/68020/clock.c
20a
	if(a->dt < 0)
		a->dt = 0;
.
17,18d
## diffname gnot/clock.c 1990/1106
## diff -e /n/bootesdump/1990/1012/sys/src/9/68020/clock.c /n/bootesdump/1990/1106/sys/src/9/68020/clock.c
116a
			if(a)
				a->dt--;
.
109,112c
		a = m->alarm;
		if(a){
			for(n=0; a && a->dt<=0 && n<NA; n++){
.
## diffname gnot/clock.c 1990/1211
## diff -e /n/bootesdump/1990/1106/sys/src/9/68020/clock.c /n/bootesdump/1990/1211/sys/src/9/68020/clock.c
108,129c
	checkalarms();
.
98d
94,96d
90d
41,79d
10,39d
## diffname gnot/clock.c 1990/1227
## diff -e /n/bootesdump/1990/1211/sys/src/9/68020/clock.c /n/bootesdump/1990/1227/sys/src/9/68020/clock.c
38c
		if(anyready())
			sched();
.
## diffname gnot/clock.c 1991/0614
## diff -e /n/bootesdump/1991/0201/sys/src/9/68020/clock.c /n/bootesdump/1991/0614/sys/src/9/gnot/clock.c
38,39c
		if(anyready()){
			if(p->hasspin)
				p->hasspin = 0;
			else
				sched();
		}
.
## diffname gnot/clock.c 1991/0710
## diff -e /n/bootesdump/1991/0614/sys/src/9/gnot/clock.c /n/bootesdump/1991/0710/sys/src/9/gnot/clock.c
44,45c
		if((ur->sr&SUPER) == 0){
			(*(ulong*)(USTKTOP-BY2WD)) += TK2MS(1);	/* profiling clock */
			if(u->nnote)
				notify(ur);
		}
.
## diffname gnot/clock.c 1991/1003
## diff -e /n/bootesdump/1991/0710/sys/src/9/gnot/clock.c /n/bootesdump/1991/1003/sys/src/9/gnot/clock.c
36a
	duartclock();
.
## diffname gnot/clock.c 1991/1007
## diff -e /n/bootesdump/1991/1003/sys/src/9/gnot/clock.c /n/bootesdump/1991/1007/sys/src/9/gnot/clock.c
37a
	kproftimer(ur->pc);
.
## diffname gnot/clock.c 1991/1108
## diff -e /n/bootesdump/1991/1007/sys/src/9/gnot/clock.c /n/bootesdump/1991/1108/sys/src/9/gnot/clock.c
47a
			if(u->p->procctl)
				procctl(u->p);
.
## diffname gnot/clock.c 1991/1112
## diff -e /n/bootesdump/1991/1108/sys/src/9/gnot/clock.c /n/bootesdump/1991/1112/sys/src/9/gnot/clock.c
48,51c
			notify(ur);
.
46c
		if(user){
.
25a
	user = (ur->sr&SUPER) == 0;
	if(user)
		u->dbgreg = ur;

.
24a
	int user;
.
## diffname gnot/clock.c 1991/1113
## diff -e /n/bootesdump/1991/1112/sys/src/9/gnot/clock.c /n/bootesdump/1991/1113/sys/src/9/gnot/clock.c
38a
	nrun = (nrdy+nrun)*1000;
	MACHP(0)->load = (MACHP(0)->load*19+nrun)/20;
.
34a
		nrun = 1;
.
25c
	int user, nrun = 0;
.
## diffname gnot/clock.c 1992/0321
## diff -e /n/bootesdump/1991/1113/sys/src/9/gnot/clock.c /n/bootesdump/1992/0321/sys/src/9/gnot/clock.c
2c
#include	"../port/lib.h"
.
## diffname gnot/clock.c 1992/0711
## diff -e /n/bootesdump/1992/0321/sys/src/9/gnot/clock.c /n/bootesdump/1992/0711/sys/src/9/gnot/clock.c
13d
## diffname gnot/clock.c 1992/0805
## diff -e /n/bootesdump/1992/0711/sys/src/9/gnot/clock.c /n/bootesdump/1992/0805/sys/src/9/gnot/clock.c
28a
		u->p->pc = ur->pc;
	}
.
27c
	if(user){
.
## diffname gnot/clock.c 1993/0226
## diff -e /n/bootesdump/1992/0805/sys/src/9/gnot/clock.c /n/bootesdump/1993/0226/sys/src/9/gnot/clock.c
46a
	mouseclock();
.
45d
## diffname gnot/clock.c 1993/0501 # deleted
## diff -e /n/bootesdump/1993/0226/sys/src/9/gnot/clock.c /n/fornaxdump/1993/0501/sys/src/brazil/gnot/clock.c
1,60d

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].