in thread/thread.cpp [1831:1855]
void semaphore::try_resume(uint64_t cnt) {
assert(cnt);
while(true) {
ScopedLockHead h(this);
if (!h) break;
auto th = (thread*)h;
auto& c = th->semaphore_count;
if (c > cnt) break;
cnt -= c;
prelocked_thread_interrupt(th, -1);
}
if (!q.th || !cnt || !m_ooo_resume)
return;
SCOPED_LOCK(q.lock);
for (auto th = q.th->next();
th!= q.th && cnt;
th = th->next()) {
SCOPED_LOCK(th->lock);
auto& c = th->semaphore_count;
if (c <= cnt) {
cnt -= c;
prelocked_thread_interrupt(th, -1);
}
}
}