Commit f5752848 authored by Akshat Kumar's avatar Akshat Kumar Committed by Rob Pike

pkg/runtime: Fix semasleep on Plan 9

With the timed semacquire patch
(kernel-tsemacquire) for Plan 9,
we can now properly do a timed
wait for the semaphore, in
semasleep.

R=golang-dev, rsc, rminnich, ality, r
CC=0intro, golang-dev, john, mirtchovski
https://golang.org/cl/6197046
parent 6dfe0162
......@@ -13,6 +13,7 @@ int32 runtime·brk_(void*);
int32 runtime·sleep(int32 ms);
int32 runtime·rfork(int32 flags, void *stk, M *m, G *g, void (*fn)(void));
int32 runtime·plan9_semacquire(uint32 *addr, int32 block);
int32 runtime·plan9_tsemacquire(uint32 *addr, int32 ms);
int32 runtime·plan9_semrelease(uint32 *addr, int32 count);
int32 runtime·notify(void (*fn)(void*, byte*));
int32 runtime·noted(int32);
......
......@@ -49,6 +49,11 @@ TEXT runtime·plan9_semacquire(SB),7,$0
INT $64
RET
TEXT runtime·plan9_tsemacquire(SB),7,$0
MOVL $52, AX
INT $64
RET
TEXT runtime·notify(SB),7,$0
MOVL $28, AX
INT $64
......
......@@ -43,7 +43,7 @@ static int32
getpid(void)
{
byte b[20], *c;
int32 fd, n;
int32 fd;
runtime·memclr(b, sizeof(b));
fd = runtime·open((byte*)"#c/pid", 0);
......@@ -276,36 +276,18 @@ runtime·semasleep(int64 ns)
int32 ms;
if(ns >= 0) {
// TODO: Plan 9 needs a new system call, tsemacquire.
// The kernel implementation is the same as semacquire
// except with a tsleep and check for timeout.
// It would be great if the implementation returned the
// value that was added to the semaphore, so that on
// timeout the return value would be 0, on success 1.
// Then the error string does not have to be parsed
// to detect timeout.
//
// If a negative time indicates no timeout, then
// semacquire can be implemented (in the kernel)
// as tsemacquire(p, v, -1).
runtime·throw("semasleep: timed sleep not implemented on Plan 9");
/*
if(ns < 0)
ms = -1;
else if(ns/1000 > 0x7fffffffll)
if(ns/1000000 > 0x7fffffffll)
ms = 0x7fffffff;
else
ms = ns/1000;
ret = runtime·plan9_tsemacquire(&m->waitsemacount, 1, ms);
ms = ns/1000000;
ret = runtime·plan9_tsemacquire(&m->waitsemacount, ms);
if(ret == 1)
return 0; // success
return -1; // timeout or interrupted
*/
}
while(runtime·plan9_semacquire(&m->waitsemacount, 1) < 0) {
/* interrupted; try again */
/* interrupted; try again (c.f. lock_sema.c) */
}
return 0; // success
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment