Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

orbis-kernel: umtx_cv_wait ABSTIME #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steady_clock should be used

.time_since_epoch()
.count();
}

while (true) {
result = ErrorCode{node->second.cv.wait(chain.mtx, ut - udiff)};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if udiff > ut, there will be big number

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
Loading