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);
getpid(void)
{
byte b[20], *c;
- int32 fd, n;
+ int32 fd;
runtime·memclr(b, sizeof(b));
fd = runtime·open((byte*)"#c/pid", 0);
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
}