orbis-kernel: shared_cv: fixed regression

This commit is contained in:
DH 2024-11-01 09:14:51 +03:00
parent 8440940945
commit 9558bb7335
2 changed files with 12 additions and 8 deletions

View file

@ -7,14 +7,16 @@ using namespace orbis;
std::errc shared_atomic32::wait_impl(std::uint32_t oldValue,
std::chrono::microseconds usec_timeout) {
auto usec_timeout_count = usec_timeout.count();
struct timespec timeout{};
timeout.tv_nsec = (usec_timeout_count % 1000'000) * 1000;
timeout.tv_sec = (usec_timeout_count / 1000'000);
int result = syscall(
SYS_futex, this, FUTEX_WAIT, oldValue,
usec_timeout != std::chrono::microseconds::max() ? &timeout : nullptr, 0,
0);
struct timespec timeout{};
bool useTimeout = usec_timeout != std::chrono::microseconds::max();
if (useTimeout) {
timeout.tv_nsec = (usec_timeout_count % 1000'000) * 1000;
timeout.tv_sec = (usec_timeout_count / 1000'000);
}
int result = syscall(SYS_futex, this, FUTEX_WAIT, oldValue,
useTimeout ? &timeout : nullptr);
if (result < 0) {
return static_cast<std::errc>(errno);

View file

@ -18,7 +18,9 @@ std::errc shared_cv::impl_wait(shared_mutex &mutex, unsigned _val,
std::errc result = {};
while (true) {
result = m_value.wait(_val, std::chrono::microseconds(usec_timeout));
result = m_value.wait(_val, usec_timeout == static_cast<std::uint64_t>(-1)
? std::chrono::microseconds::max()
: std::chrono::microseconds(usec_timeout));
// Cleanup
const auto old = m_value.fetch_op([&](unsigned &value) {