bool BlockObject::CoBlockWaitTimed(MininumTimeDurationType timeo) { auto begin = std::chrono::high_resolution_clock::now(); if (!g_Scheduler.IsCoroutine()) { while (!TryBlockWait() && std::chrono::duration_cast<MininumTimeDurationType> (std::chrono::high_resolution_clock::now() - begin) < timeo) usleep(10 * 1000); return false; } std::unique_lock<LFLock> lock(lock_); if (wakeup_ > 0) { DebugPrint(dbg_syncblock, "wait immedaitely done."); --wakeup_; return true; } lock.unlock(); Task* tk = g_Scheduler.GetLocalInfo().current_task; tk->block_ = this; tk->state_ = TaskState::sys_block; ++tk->block_sequence_; tk->block_timeout_ = timeo; tk->is_block_timeout_ = false; DebugPrint(dbg_syncblock, "wait to switch. task(%s)", tk->DebugInfo()); g_Scheduler.CoYield(); return !tk->is_block_timeout_; }
void BlockObject::CoBlockWait() { if (!g_Scheduler.IsCoroutine()) { while (!TryBlockWait()) usleep(10 * 1000); return ; } std::unique_lock<LFLock> lock(lock_); if (wakeup_ > 0) { DebugPrint(dbg_syncblock, "wait immedaitely done."); --wakeup_; return ; } Task* tk = g_Scheduler.GetLocalInfo().current_task; tk->block_ = this; tk->state_ = TaskState::sys_block; lock.unlock(); DebugPrint(dbg_syncblock, "wait to switch. task(%s)", tk->DebugInfo()); g_Scheduler.Yield(); }
void BlockObject::CoBlockWait() { if (!g_Scheduler.IsCoroutine()) { while (!TryBlockWait()) usleep(10 * 1000); return ; } std::unique_lock<LFLock> lock(lock_); if (wakeup_ > 0) { DebugPrint(dbg_syncblock, "wait immedaitely done."); --wakeup_; return ; } lock.unlock(); Task* tk = g_Scheduler.GetLocalInfo().current_task; tk->block_ = this; tk->state_ = TaskState::sys_block; tk->block_timeout_ = MininumTimeDurationType::zero(); tk->is_block_timeout_ = false; ++ tk->block_sequence_; DebugPrint(dbg_syncblock, "wait to switch. task(%s)", tk->DebugInfo()); g_Scheduler.CoYield(); }