mirror of
git://git.9front.org/plan9front/plan9front
synced 2025-01-12 11:10:06 +00:00
kernel: handle errors in semacquire
Move waserror()/poperror() out of the loop, so we can also catch errors from canacquire(). This is theoretically possible if memory has been paged out and we get I/O errors when trying to page it back in.
This commit is contained in:
parent
16c1cc99ec
commit
e38d42b4a7
2 changed files with 27 additions and 33 deletions
|
@ -109,6 +109,9 @@ putseg(Segment *s)
|
|||
} else if(decref(s) != 0)
|
||||
return;
|
||||
|
||||
assert(s->sema.prev == &s->sema);
|
||||
assert(s->sema.next = &s->sema);
|
||||
|
||||
if(s->mapsize > 0){
|
||||
emap = &s->map[s->mapsize];
|
||||
for(pte = s->map; pte < emap; pte++)
|
||||
|
|
|
@ -236,7 +236,6 @@ sysrfork(va_list list)
|
|||
wm = up->wired;
|
||||
if(wm != nil)
|
||||
procwired(p, wm->machno);
|
||||
p->psstate = nil;
|
||||
ready(p);
|
||||
sched();
|
||||
return pid;
|
||||
|
@ -1141,19 +1140,15 @@ semacquire(Segment *s, long *addr, int block)
|
|||
return 1;
|
||||
if(!block)
|
||||
return 0;
|
||||
|
||||
acquired = 0;
|
||||
semqueue(s, addr, &phore);
|
||||
if(acquired = !waserror()){
|
||||
for(;;){
|
||||
phore.waiting = 1;
|
||||
coherence();
|
||||
if(canacquire(addr)){
|
||||
acquired = 1;
|
||||
break;
|
||||
}
|
||||
if(waserror())
|
||||
if(canacquire(addr))
|
||||
break;
|
||||
sleep(&phore, semawoke, &phore);
|
||||
}
|
||||
poperror();
|
||||
}
|
||||
semdequeue(s, &phore);
|
||||
|
@ -1169,7 +1164,7 @@ semacquire(Segment *s, long *addr, int block)
|
|||
static int
|
||||
tsemacquire(Segment *s, long *addr, ulong ms)
|
||||
{
|
||||
int acquired, timedout;
|
||||
int timedout, acquired;
|
||||
ulong t;
|
||||
Sema phore;
|
||||
|
||||
|
@ -1177,36 +1172,32 @@ tsemacquire(Segment *s, long *addr, ulong ms)
|
|||
return 1;
|
||||
if(ms == 0)
|
||||
return 0;
|
||||
acquired = timedout = 0;
|
||||
timedout = 0;
|
||||
semqueue(s, addr, &phore);
|
||||
if(acquired = !waserror()){
|
||||
for(;;){
|
||||
phore.waiting = 1;
|
||||
coherence();
|
||||
if(canacquire(addr)){
|
||||
acquired = 1;
|
||||
break;
|
||||
}
|
||||
if(waserror())
|
||||
if(canacquire(addr))
|
||||
break;
|
||||
t = MACHP(0)->ticks;
|
||||
tsleep(&phore, semawoke, &phore, ms);
|
||||
t = TK2MS(MACHP(0)->ticks - t);
|
||||
poperror();
|
||||
if(t >= ms){
|
||||
timedout = 1;
|
||||
break;
|
||||
}
|
||||
ms -= t;
|
||||
}
|
||||
poperror();
|
||||
}
|
||||
semdequeue(s, &phore);
|
||||
coherence(); /* not strictly necessary due to lock in semdequeue */
|
||||
if(!phore.waiting)
|
||||
semwakeup(s, addr, 1);
|
||||
if(timedout)
|
||||
return 0;
|
||||
if(!acquired)
|
||||
nexterror();
|
||||
return 1;
|
||||
return !timedout;
|
||||
}
|
||||
|
||||
uintptr
|
||||
|
|
Loading…
Reference in a new issue