[*] Amended UNIX yield paths

This commit is contained in:
Reece Wilson 2023-03-12 20:59:03 +00:00
parent e82ec4a343
commit 1ba0519d8d
4 changed files with 23 additions and 80 deletions

View File

@ -111,47 +111,32 @@ namespace Aurora::Threading::Primitives
do
{
ret = futex_wait(&this->value_, state, &tspec);
if (ret == 0)
{
continue;
}
if (ret == EAGAIN || errno == EAGAIN)
{
continue;
}
if (ret == ETIMEDOUT || errno == ETIMEDOUT)
{
return false;
}
}
while (ret == EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(false, "semaphore timed wait failed: {}", ret)
return false;
}
else
{
int ret {};
bool bStatus {};
do
{
if ((ret = futex_wait(&this->value_, state)) == 0)
{
continue;
bStatus = true;
break;
}
if (ret == EAGAIN || errno == EAGAIN)
{
continue;
bStatus = true;
break;
}
}
while (ret == EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(false, "semaphore wait failed: {}", ret)
return false;
RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "Mutex wait failed: {}", ret)
}
state = this->value_;

View File

@ -74,6 +74,7 @@ namespace Aurora::Threading::Primitives
Time::auabsns2ts(&tspec, uEnd);
}
int ret {};
while (!this->TryLock())
{
if (uTimeout != 0)
@ -84,41 +85,27 @@ namespace Aurora::Threading::Primitives
return false;
}
int ret {};
do
{
ret = ::pthread_cond_timedwait(&this->pthreadCv_, mutex, &tspec);
if (ret == 0)
{
continue;
}
if (ret == ETIMEDOUT)
{
return false;
}
}
while (ret == EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(false, "Mutex timed wait failed: {}", ret)
return false;
}
else
{
int ret {};
bool bStatus {};
do
{
if ((ret = ::pthread_cond_wait(&this->pthreadCv_, mutex)) == 0)
{
continue;
bStatus = true;
break;
}
}
while (ret == EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(false, "Mutex wait failed: {}", ret)
return false;
RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "Mutex wait failed: {}", ret)
}
}

View File

@ -102,7 +102,6 @@ namespace Aurora::Threading::Primitives
while (!((old != 0) &&
(AuAtomicCompareExchange(&this->value_, old - 1, old) == old)))
{
if (uTimeout != 0)
{
uStart = Time::SteadyClockNS();
@ -115,47 +114,32 @@ namespace Aurora::Threading::Primitives
do
{
ret = futex_wait(&this->value_, 0, &tspec);
if (ret == 0)
{
continue;
}
if (ret == EAGAIN || errno == EAGAIN)
{
continue;
}
if (ret == ETIMEDOUT || errno == ETIMEDOUT)
{
return false;
}
}
while (ret == EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(false, "semaphore timed wait failed: {}", ret)
return false;
}
else
{
int ret {};
bool bStatus {};
do
{
if ((ret = futex_wait(&this->value_, 0)) == 0)
{
bStatus = true;
continue;
}
if (ret == EAGAIN || errno == EAGAIN)
{
bStatus = true;
continue;
}
}
while (ret == EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(false, "semaphore wait failed: {}", ret)
return false;
RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "semaphore wait failed: {}", ret)
}
old = this->value_;

View File

@ -90,39 +90,26 @@ namespace Aurora::Threading::Primitives
do
{
ret = ::pthread_cond_timedwait(&this->pthreadCv_, mutex, &tspec);
if (ret == 0)
{
continue;
}
if (ret == ETIMEDOUT)
{
return false;
}
}
while (ret == EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(false, "semaphore timed wait failed: {}", ret)
return false;
}
else
{
int ret {};
bool bStatus {};
do
{
if ((ret = ::pthread_cond_wait(&this->pthreadCv_, mutex)) == 0)
{
continue;
bStatus = true;
break;
}
}
while (ret == EINTR);
RUNTIME_ASSERT_SHUTDOWN_SAFE(false, "conditional wait failed: {}", ret)
return false;
RUNTIME_ASSERT_SHUTDOWN_SAFE(bStatus, "semaphore wait failed: {}", ret)
}
}
return true;