ref: 6a057511327e7ab355e42919a8195db582640ce0
parent: 650d794cbfb7dc130b620d4c6e2c4f1c0775c31c
author: cinap_lenrek <[email protected]>
date: Mon Jun 23 17:24:12 EDT 2014
kernel: make use of nil and 0 consistent in proc.c always explicitely compare with nil if pointer. sorry for the noise. :(
--- a/sys/src/9/port/proc.c
+++ b/sys/src/9/port/proc.c
@@ -65,10 +65,10 @@
Edf *e;
setlabel(&m->sched);
- if(up) {
- if((e = up->edf) && (e->flags & Admitted))
+ if(up != nil) {
+ if((e = up->edf) != nil && (e->flags & Admitted))
edfrecord(up);
- m->proc = 0;
+ m->proc = nil;
switch(up->state) {
case Running:
ready(up);
@@ -76,7 +76,7 @@
case Moribund:
up->state = Dead;
edfstop(up);
- if (up->edf)
+ if(up->edf != nil)
free(up->edf);
up->edf = nil;
@@ -119,10 +119,10 @@
panic("cpu%d: ilockdepth %d, last lock %#p at %#p, sched called from %#p",
m->machno,
m->ilockdepth,
- up? up->lastilock: nil,
- (up && up->lastilock)? up->lastilock->pc: 0,
+ up != nil ? up->lastilock: nil,
+ (up != nil && up->lastilock) ? up->lastilock->pc: 0,
getcallerpc(&p+2));
- if(up){
+ if(up != nil) {
/*
* Delay the sched until the process gives up the locks
* it is holding. This avoids dumb lock loops.
@@ -162,13 +162,13 @@
gotolabel(&m->sched);
}
p = runproc();
- if(!p->edf){
+ if(p->edf == nil){
updatecpu(p);
p->priority = reprioritize(p);
}
if(p != m->readied)
m->schedticks = m->ticks + HZ/10;
- m->readied = 0;
+ m->readied = nil;
up = p;
up->state = Running;
up->mach = MACHP(m->machno);
@@ -214,7 +214,7 @@
int
preempted(void)
{
- if(up && up->state == Running)
+ if(up != nil && up->state == Running)
if(up->preempted == 0)
if(anyhigher())
if(!active.exiting){
@@ -274,7 +274,7 @@
int n, t, ocpu;
int D = schedgain*HZ*Scaling;
- if(p->edf)
+ if(p->edf != nil)
return;
t = MACHP(0)->ticks*Scaling + Scaling/2;
@@ -345,8 +345,8 @@
pri = rq - runq;
lock(runq);
p->priority = pri;
- p->rnext = 0;
- if(rq->tail)
+ p->rnext = nil;
+ if(rq->tail != nil)
rq->tail->rnext = p;
else
rq->head = p;
@@ -372,8 +372,8 @@
* the queue may have changed before we locked runq,
* refind the target process.
*/
- l = 0;
- for(p = rq->head; p; p = p->rnext){
+ l = nil;
+ for(p = rq->head; p != nil; p = p->rnext){
if(p == tp)
break;
l = p;
@@ -382,13 +382,13 @@
/*
* p->mach==0 only when process state is saved
*/
- if(p == 0 || p->mach){
+ if(p == nil || p->mach != nil){
unlock(runq);
return nil;
}
- if(p->rnext == 0)
+ if(p->rnext == nil)
rq->tail = l;
- if(l)
+ if(l != nil)
l->rnext = p->rnext;
else
rq->head = p->rnext;
@@ -435,7 +435,7 @@
p->state = Ready;
queueproc(rq, p);
pt = proctrace;
- if(pt)
+ if(pt != nil)
pt(p, SReady, 0);
splx(s);
}
@@ -510,7 +510,7 @@
start = perfticks();
/* cooperative scheduling until the clock ticks */
- if((p=m->readied) && p->mach==0 && p->state==Ready
+ if((p = m->readied) != nil && p->mach == nil && p->state == Ready
&& (p->wired == nil || p->wired == MACHP(m->machno))
&& runq[Nrq-1].head == nil && runq[Nrq-2].head == nil){
skipscheds++;
@@ -534,9 +534,9 @@
*
*/
for(rq = &runq[Nrq-1]; rq >= runq; rq--){
- for(p = rq->head; p; p = p->rnext){
+ for(p = rq->head; p != nil; p = p->rnext){
if(p->mp == nil || p->mp == MACHP(m->machno)
- || (!p->wired && i > 0))
+ || (p->wired == nil && i > 0))
goto found;
}
}
@@ -564,7 +564,7 @@
edfunlock();
}
pt = proctrace;
- if(pt)
+ if(pt != nil)
pt(p, SRun, 0);
return p;
}
@@ -577,7 +577,7 @@
splhi();
lock(runq);
/* Only reliable way to see if we are Running */
- if(p->mach == 0) {
+ if(p->mach == nil) {
p->newtlb = 1;
ok = 1;
}
@@ -595,11 +595,11 @@
lock(&procalloc);
for(;;) {
- if(p = procalloc.free)
+ if((p = procalloc.free) != nil)
break;
snprint(msg, sizeof msg, "no procs; %s forking",
- up? up->text: "kernel");
+ up != nil ? up->text: "kernel");
unlock(&procalloc);
resrcwait(msg);
lock(&procalloc);
@@ -609,24 +609,24 @@
p->state = Scheding;
p->psstate = "New";
- p->mach = 0;
- p->eql = 0;
- p->qnext = 0;
+ p->mach = nil;
+ p->eql = nil;
+ p->qnext = nil;
p->nchild = 0;
p->nwait = 0;
- p->waitq = 0;
- p->parent = 0;
- p->pgrp = 0;
- p->egrp = 0;
- p->fgrp = 0;
- p->rgrp = 0;
- p->pdbg = 0;
+ p->waitq = nil;
+ p->parent = nil;
+ p->pgrp = nil;
+ p->egrp = nil;
+ p->fgrp = nil;
+ p->rgrp = nil;
+ p->pdbg = nil;
p->fpstate = FPinit;
p->kp = 0;
p->procctl = 0;
- p->syscalltrace = 0;
+ p->syscalltrace = nil;
p->notepending = 0;
- p->ureg = 0;
+ p->ureg = nil;
p->privatemem = 0;
p->noswap = 0;
p->errstr = p->errbuf0;
@@ -644,12 +644,12 @@
memset(p->seg, 0, sizeof p->seg);
p->parentpid = 0;
p->noteid = pidalloc(p);
- if(p->kstack == 0)
+ if(p->kstack == nil)
p->kstack = smalloc(KSTACK);
/* sched params */
- p->mp = 0;
- p->wired = 0;
+ p->mp = nil;
+ p->wired = nil;
procpriority(p, PriNormal, 0);
p->cpu = 0;
p->lastupdate = MACHP(0)->ticks*Scaling;
@@ -672,11 +672,11 @@
if(bm < 0){
/* pick a machine to wire to */
memset(nwired, 0, sizeof(nwired));
- p->wired = 0;
+ p->wired = nil;
pp = proctab(0);
for(i=0; i<conf.nproc; i++, pp++){
wm = pp->wired;
- if(wm && pp->pid)
+ if(wm != nil && pp->pid)
nwired[wm->machno]++;
}
bm = 0;
@@ -724,7 +724,7 @@
p = procalloc.free;
for(i=0; i<conf.nproc-1; i++,p++)
p->qnext = p+1;
- p->qnext = 0;
+ p->qnext = nil;
}
/*
@@ -748,7 +748,7 @@
up->pid, up->nlocks, up->lastlock, up->lastlock->pc, getcallerpc(&r));
lock(r);
lock(&up->rlock);
- if(r->p){
+ if(r->p != nil){
print("double sleep called from %#p, %lud %lud\n", getcallerpc(&r), r->p->pid, up->pid);
dumpstack();
}
@@ -775,7 +775,7 @@
* change state and call scheduler
*/
pt = proctrace;
- if(pt)
+ if(pt != nil)
pt(up, SSleep, 0);
up->state = Wakeme;
up->r = r;
@@ -831,8 +831,8 @@
p = t->ta;
trend = p->trend;
- p->trend = 0;
- if(trend)
+ p->trend = nil;
+ if(trend != nil)
wakeup(trend);
}
@@ -839,7 +839,7 @@
void
tsleep(Rendez *r, int (*fn)(void*), void *arg, ulong ms)
{
- if (up->tt){
+ if(up->tt != nil){
print("tsleep: timer active: mode %d, tf %#p\n", up->tmode, up->tf);
timerdel(up);
}
@@ -856,7 +856,7 @@
nexterror();
}
sleep(r, tfn, arg);
- if (up->tt)
+ if(up->tt != nil)
timerdel(up);
up->twhen = 0;
poperror();
@@ -969,21 +969,21 @@
switch(p->state){
case Queueing:
/* Try and pull out of a eqlock */
- if(q = p->eql){
+ if((q = p->eql) != nil){
lock(&q->use);
if(p->state == Queueing && p->eql == q){
Proc *d, *l;
- for(l = nil, d = q->head; d; l = d, d = d->qnext){
+ for(l = nil, d = q->head; d != nil; l = d, d = d->qnext){
if(d == p){
- if(l)
+ if(l != nil)
l->qnext = p->qnext;
else
q->head = p->qnext;
- if(p->qnext == 0)
+ if(p->qnext == nil)
q->tail = l;
- p->qnext = 0;
- p->eql = 0; /* not taken */
+ p->qnext = nil;
+ p->eql = nil; /* not taken */
ready(p);
break;
}
@@ -999,7 +999,7 @@
Proc *d, **l;
l = &REND(p->rgrp, p->rendtag);
- for(d = *l; d; d = d->rendhash) {
+ for(d = *l; d != nil; d = d->rendhash) {
if(d == p) {
*l = p->rendhash;
p->rendval = ~0;
@@ -1040,7 +1040,7 @@
edfstop(up);
p->state = Broken;
- p->psstate = 0;
+ p->psstate = nil;
sched();
}
@@ -1070,7 +1070,7 @@
n = broken.n;
for(i=0; i<n; i++) {
ready(broken.p[i]);
- broken.p[i] = 0;
+ broken.p[i] = nil;
}
broken.n = 0;
qunlock(&broken);
@@ -1092,10 +1092,10 @@
void (*pt)(Proc*, int, vlong);
up->alarm = 0;
- if (up->tt)
+ if(up->tt != nil)
timerdel(up);
pt = proctrace;
- if(pt)
+ if(pt != nil)
pt(up, SDead, 0);
/* nil out all the resources under lock (free later) */
@@ -1112,15 +1112,15 @@
up->dot = nil;
qunlock(&up->debug);
- if(fgrp)
+ if(fgrp != nil)
closefgrp(fgrp);
- if(egrp)
+ if(egrp != nil)
closeegrp(egrp);
- if(rgrp)
+ if(rgrp != nil)
closergrp(rgrp);
- if(dot)
+ if(dot != nil)
cclose(dot);
- if(pgrp)
+ if(pgrp != nil)
closepgrp(pgrp);
/*
@@ -1135,7 +1135,7 @@
wq->w.time[TUser] = tk2ms(utime);
wq->w.time[TSys] = tk2ms(stime);
wq->w.time[TReal] = tk2ms(MACHP(0)->ticks - up->time[TReal]);
- if(exitstr && exitstr[0])
+ if(exitstr != nil && exitstr[0])
snprint(wq->w.msg, sizeof(wq->w.msg), "%s %lud: %s", up->text, up->pid, exitstr);
else
wq->w.msg[0] = '\0';
@@ -1165,11 +1165,11 @@
}
}
unlock(&p->exl);
- if(wq)
+ if(wq != nil)
free(wq);
}
- else if(up->kp == 0 && up->parent == 0){
- if(exitstr == 0)
+ else if(up->kp == 0 && up->parent == nil){
+ if(exitstr == nil)
exitstr = "unknown";
panic("boot process died: %s", exitstr);
}
@@ -1180,9 +1180,9 @@
qlock(&up->seglock);
es = &up->seg[NSEG];
for(s = up->seg; s < es; s++) {
- if(*s) {
+ if(*s != nil) {
putseg(*s);
- *s = 0;
+ *s = nil;
}
}
qunlock(&up->seglock);
@@ -1193,7 +1193,7 @@
wakeup(&up->waitr);
unlock(&up->exl);
- while((wq = up->waitq) != 0){
+ while((wq = up->waitq) != nil){
up->waitq = wq->next;
free(wq);
}
@@ -1200,13 +1200,13 @@
/* release debuggers */
qlock(&up->debug);
- if(up->pdbg) {
+ if(up->pdbg != nil) {
wakeup(&up->pdbg->sleep);
- up->pdbg = 0;
+ up->pdbg = nil;
}
- if(up->syscalltrace) {
+ if(up->syscalltrace != nil) {
free(up->syscalltrace);
- up->syscalltrace = 0;
+ up->syscalltrace = nil;
}
qunlock(&up->debug);
@@ -1244,7 +1244,7 @@
}
lock(&up->exl);
- while(up->waitq == 0) {
+ while(up->waitq == nil) {
if(up->nchild == 0) {
unlock(&up->exl);
error(Enochild);
@@ -1261,7 +1261,7 @@
qunlock(&up->qwaitr);
poperror();
- if(w)
+ if(w != nil)
memmove(w, &wq->w, sizeof(Waitmsg));
cpid = wq->w.pid;
free(wq);
@@ -1280,15 +1280,15 @@
ulong bss;
char *s;
- if(p == 0)
+ if(p == nil)
return;
bss = 0;
- if(p->seg[BSEG])
+ if(p->seg[BSEG] != nil)
bss = p->seg[BSEG]->top;
s = p->psstate;
- if(s == 0)
+ if(s == nil)
s = statename[p->state];
print("%3lud:%10s pc %#p dbgpc %#p %8s (%s) ut %ld st %ld bss %lux qpc %#p nl %d nd %lud lpc %#p pri %lud\n",
p->pid, p->text, p->pc, dbgpc(p), s, statename[p->state],
@@ -1302,7 +1302,7 @@
int i;
Proc *p;
- if(up)
+ if(up != nil)
print("up %lud\n", up->pid);
else
print("no current process\n");
@@ -1366,10 +1366,10 @@
Schedq *rq;
for(rq = &runq[Nrq-1]; rq >= runq; rq--){
- if(rq->head == 0)
+ if(rq->head == nil)
continue;
print("rq%ld:", rq-runq);
- for(p = rq->head; p; p = p->rnext)
+ for(p = rq->head; p != nil; p = p->rnext)
print(" %lud(%lud)", p->pid, m->ticks - p->readytime);
print("\n");
delay(150);
@@ -1384,7 +1384,7 @@
static Pgrp *kpgrp;
p = newproc();
- p->psstate = 0;
+ p->psstate = nil;
p->procmode = 0640;
p->kp = 1;
p->noswap = 1;
@@ -1394,7 +1394,7 @@
p->nerrlab = 0;
p->slash = up->slash;
p->dot = up->dot;
- if(p->dot)
+ if(p->dot != nil)
incref(p->dot);
memmove(p->note, up->note, sizeof(p->note));
@@ -1402,8 +1402,8 @@
p->notified = 0;
p->lastnote = up->lastnote;
p->notify = up->notify;
- p->ureg = 0;
- p->dbgreg = 0;
+ p->ureg = nil;
+ p->dbgreg = nil;
procpriority(p, PriKproc, 0);
@@ -1411,7 +1411,7 @@
kstrdup(&p->user, eve);
kstrdup(&p->text, name);
- if(kpgrp == 0)
+ if(kpgrp == nil)
kpgrp = newpgrp();
p->pgrp = kpgrp;
incref(kpgrp);
@@ -1453,9 +1453,9 @@
/* free a waiting debugger */
s = spllo();
qlock(&p->debug);
- if(p->pdbg) {
+ if(p->pdbg != nil) {
wakeup(&p->pdbg->sleep);
- p->pdbg = 0;
+ p->pdbg = nil;
}
qunlock(&p->debug);
splhi();
@@ -1506,7 +1506,7 @@
Proc *p, *ep, *kp;
max = 0;
- kp = 0;
+ kp = nil;
ep = procalloc.arena+conf.nproc;
for(p = procalloc.arena; p < ep; p++) {
if(p->state == Dead || p->kp || !canqlock(&p->seglock))
@@ -1525,13 +1525,13 @@
max = l;
}
}
- if(kp == 0 || !canqlock(&kp->seglock))
+ if(kp == nil || !canqlock(&kp->seglock))
return;
print("%lud: %s killed: %s\n", kp->pid, kp->text, why);
for(p = procalloc.arena; p < ep; p++) {
if(p->state == Dead || p->kp)
continue;
- if(p != kp && p->seg[BSEG] && p->seg[BSEG] == kp->seg[BSEG])
+ if(p != kp && p->seg[BSEG] != nil && p->seg[BSEG] == kp->seg[BSEG])
p->procctl = Proc_exitbig;
}
kp->procctl = Proc_exitbig;
@@ -1571,7 +1571,7 @@
static ulong nrun;
p = m->proc;
- if(p) {
+ if(p != nil) {
nrun++;
p->time[p->insyscall]++;
}
@@ -1628,7 +1628,7 @@
for(x = procalloc.ht[h]; x != nil; x = x->pidhash)
if(x->pid == pid)
goto Retry;
- if(p){
+ if(p != nil){
p->pid = pid;
p->pidhash = procalloc.ht[h];
procalloc.ht[h] = p;