Fix TestThread.c and POSIX semaphore
This commit is contained in:
@@ -64,9 +64,11 @@ int BH_SemaphoreWaitFor(BH_Semaphore *semaphore,
|
|||||||
if (convertToTimespec(&ts, timeout))
|
if (convertToTimespec(&ts, timeout))
|
||||||
return BH_ERROR;
|
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;
|
case ETIMEDOUT: return BH_TIMEOUT;
|
||||||
default: return BH_ERROR;
|
default: return BH_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ BH_UNIT_TEST(Semaphore)
|
|||||||
BH_VERIFY((semaphore = BH_SemaphoreNew(1)) != NULL);
|
BH_VERIFY((semaphore = BH_SemaphoreNew(1)) != NULL);
|
||||||
BH_VERIFY(BH_SemaphoreWait(semaphore) == BH_OK);
|
BH_VERIFY(BH_SemaphoreWait(semaphore) == BH_OK);
|
||||||
BH_VERIFY(BH_SemaphoreTryWait(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_SemaphorePost(semaphore) == BH_OK);
|
||||||
BH_VERIFY(BH_SemaphoreTryWait(semaphore) == BH_OK);
|
BH_VERIFY(BH_SemaphoreTryWait(semaphore) == BH_OK);
|
||||||
BH_VERIFY(BH_SemaphorePost(semaphore) == BH_OK);
|
BH_VERIFY(BH_SemaphorePost(semaphore) == BH_OK);
|
||||||
@@ -50,7 +50,7 @@ BH_UNIT_TEST(Condition)
|
|||||||
start = time(NULL);
|
start = time(NULL);
|
||||||
BH_VERIFY((condition = BH_ConditionNew()) != NULL);
|
BH_VERIFY((condition = BH_ConditionNew()) != NULL);
|
||||||
BH_VERIFY((mutex = BH_MutexNew()) != 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_ConditionSignal(condition) == BH_OK);
|
||||||
BH_VERIFY(BH_ConditionBroadcast(condition) == BH_OK);
|
BH_VERIFY(BH_ConditionBroadcast(condition) == BH_OK);
|
||||||
BH_VERIFY(time(NULL) - start >= 5);
|
BH_VERIFY(time(NULL) - start >= 5);
|
||||||
|
|||||||
Reference in New Issue
Block a user