]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make notetsleep() return false if timeout happens
authorDmitriy Vyukov <dvyukov@google.com>
Wed, 29 May 2013 07:49:45 +0000 (11:49 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Wed, 29 May 2013 07:49:45 +0000 (11:49 +0400)
This is needed for preemptive scheduler, because during
stoptheworld we want to wait with timeout and re-preempt
M's on timeout.

R=golang-dev, remyoudompheng, iant
CC=golang-dev
https://golang.org/cl/9375043

src/pkg/runtime/lock_futex.c
src/pkg/runtime/lock_sema.c
src/pkg/runtime/runtime.h

index d20b63c329b3bafb3e3737837fb288069e191530..5309a21a13adcb17ba9213bb61f202b9bc42eae9 100644 (file)
@@ -127,18 +127,18 @@ runtime·notesleep(Note *n)
                runtime·setprof(true);
 }
 
-void
+bool
 runtime·notetsleep(Note *n, int64 ns)
 {
        int64 deadline, now;
 
        if(ns < 0) {
                runtime·notesleep(n);
-               return;
+               return true;
        }
 
        if(runtime·atomicload((uint32*)&n->key) != 0)
-               return;
+               return true;
 
        if(m->profilehz > 0)
                runtime·setprof(false);
@@ -154,4 +154,5 @@ runtime·notetsleep(Note *n, int64 ns)
        }
        if(m->profilehz > 0)
                runtime·setprof(true);
+       return runtime·atomicload((uint32*)&n->key) != 0;
 }
index 80674e8a5e3d0011cf188f605eafb492dc9a31d7..be4d306d1f4888f0d1070dfe574b4ecdc140bf16 100644 (file)
@@ -161,7 +161,7 @@ runtime·notesleep(Note *n)
                runtime·setprof(true);
 }
 
-void
+bool
 runtime·notetsleep(Note *n, int64 ns)
 {
        M *mp;
@@ -169,7 +169,7 @@ runtime·notetsleep(Note *n, int64 ns)
 
        if(ns < 0) {
                runtime·notesleep(n);
-               return;
+               return true;
        }
 
        if(m->waitsema == 0)
@@ -179,7 +179,7 @@ runtime·notetsleep(Note *n, int64 ns)
        if(!runtime·casp((void**)&n->key, nil, m)) {  // must be LOCKED (got wakeup already)
                if(n->key != LOCKED)
                        runtime·throw("notetsleep - waitm out of sync");
-               return;
+               return true;
        }
 
        if(m->profilehz > 0)
@@ -192,7 +192,7 @@ runtime·notetsleep(Note *n, int64 ns)
                        // Done.
                        if(m->profilehz > 0)
                                runtime·setprof(true);
-                       return;
+                       return true;
                }
 
                // Interrupted or timed out.  Still registered.  Semaphore not acquired.
@@ -216,13 +216,13 @@ runtime·notetsleep(Note *n, int64 ns)
                if(mp == m) {
                        // No wakeup yet; unregister if possible.
                        if(runtime·casp((void**)&n->key, mp, nil))
-                               return;
+                               return false;
                } else if(mp == (M*)LOCKED) {
                        // Wakeup happened so semaphore is available.
                        // Grab it to avoid getting out of sync.
                        if(runtime·semasleep(-1) < 0)
                                runtime·throw("runtime: unable to acquire - semaphore out of sync");
-                       return;
+                       return true;
                } else {
                        runtime·throw("runtime: unexpected waitm - semaphore out of sync");
                }
index c7ade2beb57c72674207992c90498a0607323652..2d918f4cff57735e028deb404a56e076e3858fab 100644 (file)
@@ -862,7 +862,7 @@ void        runtime·unlock(Lock*);
 void   runtime·noteclear(Note*);
 void   runtime·notesleep(Note*);
 void   runtime·notewakeup(Note*);
-void   runtime·notetsleep(Note*, int64);
+bool   runtime·notetsleep(Note*, int64);  // false - timeout
 
 /*
  * low-level synchronization for implementing the above