aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Platform/Posix/Semaphore.c6
-rw-r--r--test/src/TestThread.c4
2 files changed, 6 insertions, 4 deletions
diff --git a/src/Platform/Posix/Semaphore.c b/src/Platform/Posix/Semaphore.c
index 2fb03a1..e4c5f5b 100644
--- a/src/Platform/Posix/Semaphore.c
+++ b/src/Platform/Posix/Semaphore.c
@@ -64,9 +64,11 @@ int BH_SemaphoreWaitFor(BH_Semaphore *semaphore,
if (convertToTimespec(&ts, timeout))
return BH_ERROR;
- switch (sem_timedwait(&semaphore->handle, &ts))
+ if (!sem_timedwait(&semaphore->handle, &ts))
+ return BH_OK;
+
+ switch (errno)
{
- case 0: return BH_OK;
case ETIMEDOUT: return BH_TIMEOUT;
default: return BH_ERROR;
}
diff --git a/test/src/TestThread.c b/test/src/TestThread.c
index 1b82ca1..e8e9ad0 100644
--- a/test/src/TestThread.c
+++ b/test/src/TestThread.c
@@ -28,7 +28,7 @@ BH_UNIT_TEST(Semaphore)
BH_VERIFY((semaphore = BH_SemaphoreNew(1)) != NULL);
BH_VERIFY(BH_SemaphoreWait(semaphore) == BH_OK);
BH_VERIFY(BH_SemaphoreTryWait(semaphore) != BH_OK);
- BH_VERIFY(BH_SemaphoreWaitFor(semaphore, 5000) != BH_OK);
+ BH_VERIFY(BH_SemaphoreWaitFor(semaphore, 5000) == BH_TIMEOUT);
BH_VERIFY(BH_SemaphorePost(semaphore) == BH_OK);
BH_VERIFY(BH_SemaphoreTryWait(semaphore) == BH_OK);
BH_VERIFY(BH_SemaphorePost(semaphore) == BH_OK);
@@ -50,7 +50,7 @@ BH_UNIT_TEST(Condition)
start = time(NULL);
BH_VERIFY((condition = BH_ConditionNew()) != NULL);
BH_VERIFY((mutex = BH_MutexNew()) != NULL);
- BH_VERIFY(BH_ConditionWaitFor(condition, mutex, 5000) != BH_OK);
+ BH_VERIFY(BH_ConditionWaitFor(condition, mutex, 5000) == BH_TIMEOUT);
BH_VERIFY(BH_ConditionSignal(condition) == BH_OK);
BH_VERIFY(BH_ConditionBroadcast(condition) == BH_OK);
BH_VERIFY(time(NULL) - start >= 5);