diff options
| author | Mikhail Romanko <me@blankhex.com> | 2025-08-28 17:28:07 +0300 |
|---|---|---|
| committer | Mikhail Romanko <me@blankhex.com> | 2025-08-28 17:28:07 +0300 |
| commit | 12a00c351543d0e10f242d4c4b6f0127db0cb6a1 (patch) | |
| tree | 6b2290178ac13f96a9efcd1a53fb647621063207 | |
| parent | 377247bbe1d87dd5e04e0a19828e135193dc8d3b (diff) | |
| download | bhlib-12a00c351543d0e10f242d4c4b6f0127db0cb6a1.tar.gz | |
Fix TestThread.c and POSIX semaphore
| -rw-r--r-- | src/Platform/Posix/Semaphore.c | 6 | ||||
| -rw-r--r-- | test/src/TestThread.c | 4 |
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); |
