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);
}
if(m->profilehz > 0)
runtime·setprof(true);
+ return runtime·atomicload((uint32*)&n->key) != 0;
}
runtime·setprof(true);
}
-void
+bool
runtime·notetsleep(Note *n, int64 ns)
{
M *mp;
if(ns < 0) {
runtime·notesleep(n);
- return;
+ return true;
}
if(m->waitsema == 0)
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)
// Done.
if(m->profilehz > 0)
runtime·setprof(true);
- return;
+ return true;
}
// Interrupted or timed out. Still registered. Semaphore not acquired.
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");
}
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