1
0
mirror of https://github.com/golang/go synced 2024-11-23 00:40:08 -07:00

runtime: make notetsleep() return false if timeout happens

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
This commit is contained in:
Dmitriy Vyukov 2013-05-29 11:49:45 +04:00
parent 605da0e2a2
commit e932c2035f
3 changed files with 11 additions and 10 deletions

View 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;
}

View 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");
}

View 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