shared_mutex fix (linux)

This commit is contained in:
Nekotekina 2017-02-24 18:48:53 +03:00
parent 8369cb2af6
commit f35babad98
3 changed files with 88 additions and 22 deletions

View file

@ -1,6 +1,10 @@
#include "cond.h"
#include "sync.h"
#ifndef _WIN32
#include <thread>
#endif
bool cond_variable::imp_wait(u32 _old, u64 _timeout) noexcept
{
verify(HERE), _old != -1; // Very unlikely: it requires 2^32 distinct threads to wait simultaneously
@ -69,7 +73,7 @@ void cond_variable::imp_wake(u32 _count) noexcept
NtReleaseKeyedEvent(nullptr, &m_value, false, nullptr);
}
#else
for (u32 i = _count; i > 0; sched_yield())
for (u32 i = _count; i > 0; std::this_thread::yield())
{
const u32 value = m_value;
@ -87,7 +91,7 @@ void cond_variable::imp_wake(u32 _count) noexcept
if (const int res = futex((int*)&m_value.raw(), FUTEX_WAKE_PRIVATE, i > INT_MAX ? INT_MAX : i, nullptr, nullptr, 0))
{
verify(HERE), res >= 0 && res <= i;
verify(HERE), res >= 0 && (u32)res <= i;
i -= res;
}