From e981bf3f12857033ae8cb9e50c8d516b0c79ae8f Mon Sep 17 00:00:00 2001 From: Ivan Chikish Date: Tue, 18 Jul 2023 19:13:11 +0300 Subject: [PATCH] [orbis-kernel] Fix sys_evf_wait timeout+ --- orbis-kernel/src/evf.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/orbis-kernel/src/evf.cpp b/orbis-kernel/src/evf.cpp index 20298f799..240bd0aa7 100644 --- a/orbis-kernel/src/evf.cpp +++ b/orbis-kernel/src/evf.cpp @@ -15,16 +15,20 @@ orbis::ErrorCode orbis::EventFlag::wait(Thread *thread, std::uint8_t waitMode, using namespace std::chrono; steady_clock::time_point start{}; - if (timeout) - start = steady_clock::now(); uint64_t elapsed = 0; + uint64_t fullTimeout = -1; + if (timeout) { + start = steady_clock::now(); + fullTimeout = *timeout; + } auto update_timeout = [&] { if (!timeout) return; auto now = steady_clock::now(); elapsed = duration_cast(now - start).count(); - if (*timeout >= elapsed) { + if (fullTimeout > elapsed) { + *timeout = fullTimeout - elapsed; return; } *timeout = 0; @@ -86,7 +90,7 @@ orbis::ErrorCode orbis::EventFlag::wait(Thread *thread, std::uint8_t waitMode, waitingThreads[position] = waitingThread; if (timeout) { - cv.wait(queueMtx, *timeout - elapsed); + cv.wait(queueMtx, *timeout); update_timeout(); continue; }