Skip to content

Commit

Permalink
POSIX compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlWachter committed Jun 4, 2024
1 parent e60ff3a commit b5873dd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
19 changes: 10 additions & 9 deletions platform/hermit/pte_osal.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,31 +404,31 @@ pte_osResult pte_osMutexCreate(pte_osMutexHandle *pHandle)

pte_osResult pte_osMutexDelete(pte_osMutexHandle handle)
{
if (sys_sem_destroy(handle))
if (sys_sem_destroy(&handle))
return PTE_OS_NO_RESOURCES;

return PTE_OS_OK;
}

pte_osResult pte_osMutexLock(pte_osMutexHandle handle)
{
if (sys_sem_wait(handle))
if (sys_sem_wait(&handle))
return PTE_OS_NO_RESOURCES;

return PTE_OS_OK;
}

pte_osResult pte_osMutexTimedLock(pte_osMutexHandle handle, unsigned int timeoutMsecs)
{
if (sys_sem_timedwait(handle, timeoutMsecs))
if (sys_sem_timedwait(&handle, timeoutMsecs))
return PTE_OS_TIMEOUT;

return PTE_OS_OK;
}

pte_osResult pte_osMutexUnlock(pte_osMutexHandle handle)
{
if (sys_sem_post(handle))
if (sys_sem_post(&handle))
return PTE_OS_NO_RESOURCES;

return PTE_OS_OK;
Expand All @@ -442,6 +442,7 @@ pte_osResult pte_osMutexUnlock(pte_osMutexHandle handle)

pte_osResult pte_osSemaphoreCreate(int initialValue, pte_osSemaphoreHandle *pHandle)
{

if (sys_sem_init(pHandle, 0, initialValue))
return PTE_OS_NO_RESOURCES;

Expand All @@ -450,7 +451,7 @@ pte_osResult pte_osSemaphoreCreate(int initialValue, pte_osSemaphoreHandle *pHan

pte_osResult pte_osSemaphoreDelete(pte_osSemaphoreHandle handle)
{
if (sys_sem_destroy(handle))
if (sys_sem_destroy(&handle))
return PTE_OS_NO_RESOURCES;

return PTE_OS_OK;
Expand All @@ -461,7 +462,7 @@ pte_osResult pte_osSemaphorePost(pte_osSemaphoreHandle handle, int count)
int i;

for (i=0; i<count; i++) {
if (sys_sem_post(handle)) {
if (sys_sem_post(&handle)) {
return PTE_OS_NO_RESOURCES;
}
}
Expand All @@ -471,11 +472,11 @@ pte_osResult pte_osSemaphorePost(pte_osSemaphoreHandle handle, int count)
pte_osResult pte_osSemaphorePend(pte_osSemaphoreHandle handle, unsigned int *pTimeoutMsecs)
{
if (pTimeoutMsecs && *pTimeoutMsecs) {
if (sys_sem_timedwait(handle, *pTimeoutMsecs)) {
if (sys_sem_timedwait(&handle, *pTimeoutMsecs)) {
return PTE_OS_TIMEOUT;
}
} else {
if (sys_sem_wait(handle)) {
if (sys_sem_wait(&handle)) {
return PTE_OS_NO_RESOURCES;
}
}
Expand All @@ -494,7 +495,7 @@ pte_osResult pte_osSemaphoreCancellablePend(pte_osSemaphoreHandle semHandle, uns

if (pTimeout)
msec = *pTimeout;
ret = sys_sem_timedwait(semHandle, msec);
ret = sys_sem_timedwait(&semHandle, msec);

if (ret == -ETIME)
return PTE_OS_TIMEOUT;
Expand Down
4 changes: 2 additions & 2 deletions platform/hermit/pte_osal.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "syscall.h"

typedef void* pte_osThreadHandle;
typedef HermitSemaphore* pte_osSemaphoreHandle;
typedef HermitSemaphore* pte_osMutexHandle;
typedef HermitSemaphore pte_osSemaphoreHandle;
typedef HermitSemaphore pte_osMutexHandle;

#define OS_MAX_SIMUL_THREADS 32
#define OS_DEFAULT_PRIO 8
Expand Down
7 changes: 3 additions & 4 deletions platform/hermit/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ extern "C" {
struct _HermitRecursiveMutex;
typedef struct _HermitRecursiveMutex HermitRecursiveMutex;

struct _HermitSemaphore;
typedef struct _HermitSemaphore HermitSemaphore;
typedef void* HermitSemaphore;

struct _HermitSpinlock;
typedef struct _HermitSpinlock HermitSpinlock;
Expand Down Expand Up @@ -113,11 +112,11 @@ int sys_recmutex_init(HermitRecursiveMutex** recmutex);
int sys_recmutex_destroy(HermitRecursiveMutex* recmutex);
int sys_recmutex_lock(HermitRecursiveMutex* recmutex);
int sys_recmutex_unlock(HermitRecursiveMutex* recmutex);
int sys_sem_init(HermitSemaphore** sem, unsigned int pshared, unsigned int value);
int sys_sem_init(HermitSemaphore* sem, unsigned int pshared, unsigned int value);
int sys_sem_destroy(HermitSemaphore* sem);
int sys_sem_post(HermitSemaphore* sem);
int sys_sem_trywait(HermitSemaphore* sem);
int sys_sem_timedwait(HermitSemaphore *sem, unsigned int ms);
int sys_sem_timedwait(HermitSemaphore* sem, unsigned int ms);
#define sys_sem_wait(sem) sys_sem_timedwait(sem, 0)
int sys_sem_timedwait(HermitSemaphore* sem, unsigned int ms);
int sys_spinlock_init(HermitSpinlock** lock);
Expand Down

0 comments on commit b5873dd

Please sign in to comment.