Skip to content

Commit

Permalink
orbis-kernel: umtx_cv_wait ABSTIME
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Oct 16, 2024
1 parent 370b969 commit 0630abd
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions orbis-kernel/src/umtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,22 +311,6 @@ orbis::ErrorCode orbis::umtx_cv_wait(Thread *thread, ptr<ucond> cv,
return ErrorCode::NOSYS;

}
if ((wflags & kCvWaitAbsTime) != 0 && ut + 1) {
ORBIS_LOG_WARNING("umtx_cv_wait: ABSTIME unimplemented", wflags);
auto now = std::chrono::time_point_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now())
.time_since_epoch()
.count();

if (now > ut) {
ut = 0;
} else {
ut = ut - now;
}

std::abort();
return ErrorCode::NOSYS;
}

auto [chain, key, lock] = g_context.getUmtxChain0(thread, cv->flags, cv);
auto node = chain.enqueue(key, thread);
Expand All @@ -347,14 +331,26 @@ orbis::ErrorCode orbis::umtx_cv_wait(Thread *thread, ptr<ucond> cv,
} else {
auto start = std::chrono::steady_clock::now();
std::uint64_t udiff = 0;

if ((wflags & kCvWaitAbsTime) != 0) {
udiff = std::chrono::time_point_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now())
.time_since_epoch()
.count();
}

while (true) {
result = ErrorCode{node->second.cv.wait(chain.mtx, ut - udiff)};
if (node->second.thr != thread) {
break;
}
udiff = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - start)
.count();

if ((wflags & kCvWaitAbsTime) == 0) {
udiff = std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::steady_clock::now() - start)
.count();
}

if (udiff >= ut) {
result = ErrorCode::TIMEDOUT;
break;
Expand Down

0 comments on commit 0630abd

Please sign in to comment.