aboutsummaryrefslogtreecommitdiff
path: root/src/Platform/Posix/Semaphore.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Platform/Posix/Semaphore.c')
-rw-r--r--src/Platform/Posix/Semaphore.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/src/Platform/Posix/Semaphore.c b/src/Platform/Posix/Semaphore.c
index aeaf3bd..9482201 100644
--- a/src/Platform/Posix/Semaphore.c
+++ b/src/Platform/Posix/Semaphore.c
@@ -1,4 +1,5 @@
#include "Thread.h"
+#include "Timespec.h"
#include <stdlib.h>
#include <errno.h>
@@ -47,7 +48,7 @@ int BH_SemaphoreWait(BH_Semaphore *semaphore)
}
-int BH_SemaphoreWaitTry(BH_Semaphore *semaphore)
+int BH_SemaphoreTryWait(BH_Semaphore *semaphore)
{
if (sem_trywait(&semaphore->handle))
return BH_ERROR;
@@ -60,15 +61,7 @@ int BH_SemaphoreWaitFor(BH_Semaphore *semaphore,
uint32_t timeout)
{
struct timespec ts;
-
- /* Calculate absoulute time for timed wait */
- clock_gettime(CLOCK_REALTIME, &ts);
- ts.tv_sec += timeout / 1000;
- ts.tv_nsec += (timeout % 1000) * 1000000;
- while (ts.tv_nsec >= 1000000000) {
- ts.tv_nsec -= 1000000000;
- ts.tv_sec += 1;
- }
+ convertToTimespec(&ts, timeout);
switch (sem_timedwait(&semaphore->handle, &ts))
{
@@ -147,7 +140,7 @@ int BH_SemaphoreWait(BH_Semaphore *semaphore)
}
-int BH_SemaphoreWaitTry(BH_Semaphore *semaphore)
+int BH_SemaphoreTryWait(BH_Semaphore *semaphore)
{
int result;
@@ -172,13 +165,7 @@ int BH_SemaphoreWaitFor(BH_Semaphore *semaphore,
struct timespec ts;
/* Calculate absoulute time for timed wait */
- clock_gettime(CLOCK_REALTIME, &ts);
- ts.tv_sec += timeout / 1000;
- ts.tv_nsec += (timeout % 1000) * 1000000;
- while (ts.tv_nsec >= 1000000000) {
- ts.tv_nsec -= 1000000000;
- ts.tv_sec += 1;
- }
+ convertToTimespec(&ts, timeout);
result = BH_OK;
/* Wait until semaphore count is not zero or timeout */