bool wait(duration_t* timeout) { std::unique_lock<std::mutex> guard(mutex); queue_lock->unlock(); std::cv_status res = std::cv_status::no_timeout; if(timeout) { auto start = std::chrono::system_clock::now(); res = ready.wait_for(guard, *timeout); *timeout -= (std::chrono::system_clock::now() - start); } else { ready.wait(guard); } guard.unlock(); queue_lock->lock(); return res == std::cv_status::no_timeout; }
void before_switch_to() { lock->lock(); }