]> Cypherpunks repositories - gostls13.git/commitdiff
pkg/runtime: Fix semasleep on Plan 9
authorAkshat Kumar <seed@mail.nanosouffle.net>
Wed, 16 May 2012 22:09:28 +0000 (15:09 -0700)
committerRob Pike <r@golang.org>
Wed, 16 May 2012 22:09:28 +0000 (15:09 -0700)
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

src/pkg/runtime/os_plan9.h
src/pkg/runtime/sys_plan9_386.s
src/pkg/runtime/thread_plan9.c

index cc14cc8c5e5483feddca6527187f63a8e3573f28..6f1f0bb8eb0c4bbc7b9d0b068ba3242d08cfcf97 100644 (file)
@@ -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);
index f3e56d689b38ac69933a619b830e96c2b0d7e682..cdcf0b27982c75a119e0212687af5f65d44b4e43 100644 (file)
@@ -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
index e951e31c097ae51a16f8bd01927097bf856417fc..57d535713d2bb44a4deaad8122aff545df8459cb 100644 (file)
@@ -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
 }