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

Cherry pick PR #3998: Fix deadlock caused by timeout overflow #4140

Merged
merged 1 commit into from
Sep 21, 2024
Merged
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
11 changes: 11 additions & 0 deletions starboard/common/condition_variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,24 @@ bool ConditionVariable::WaitTimed(int64_t duration) const {
bool was_signaled = SbConditionVariableIsSignaled(
SbConditionVariableWaitTimed(&condition_, mutex_->mutex(), duration));
#else
if (duration < 0) {
duration = 0;
}
#if !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT)
int64_t timeout_time_usec = starboard::CurrentMonotonicTime();
#else
int64_t timeout_time_usec = starboard::CurrentPosixTime();
#endif // !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT)
timeout_time_usec += duration;

// Detect overflow if timeout is near kSbInt64Max. Since timeout can't be
// negative at this point, if it goes negative after adding now, we know we've
// gone over. Especially posix now, which has a 400 year advantage over
// Chromium (Windows) now.
if (timeout_time_usec < 0) {
timeout_time_usec = kSbInt64Max;
}

struct timespec timeout;
timeout.tv_sec = timeout_time_usec / 1000'000;
timeout.tv_nsec = (timeout_time_usec % 1000'000) * 1000;
Expand Down
Loading