Skip to content

Commit

Permalink
Merge pull request #2 from CarlWachter/path2rs
Browse files Browse the repository at this point in the history
POSIX compatibility
  • Loading branch information
mkroening authored Jun 4, 2024
2 parents a7352b4 + 49bdfa7 commit 0bc9645
Show file tree
Hide file tree
Showing 4 changed files with 941 additions and 20 deletions.
24 changes: 12 additions & 12 deletions platform/hermit/pte_osal.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,39 +396,39 @@ int pte_osThreadGetDefaultPriority(void)

pte_osResult pte_osMutexCreate(pte_osMutexHandle *pHandle)
{
if (sys_sem_init(pHandle, 1))
if (sys_sem_init(pHandle, 0, 1))
return PTE_OS_NO_RESOURCES;

return PTE_OS_OK;
}

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,15 +442,16 @@ pte_osResult pte_osMutexUnlock(pte_osMutexHandle handle)

pte_osResult pte_osSemaphoreCreate(int initialValue, pte_osSemaphoreHandle *pHandle)
{
if (sys_sem_init(pHandle, initialValue))

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

return PTE_OS_OK;
}

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,22 +462,21 @@ 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;
}
}

return PTE_OS_OK;
}

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 @@ -495,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
8 changes: 3 additions & 5 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 All @@ -84,7 +83,6 @@ typedef void (*signal_handler_t)(int);
#define LOW_PRIO 1
#define IDLE_PRIO 0


/*
* HermitCore is a libOS.
* => classical system calls are realized as normal function
Expand Down Expand Up @@ -114,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 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
Loading

0 comments on commit 0bc9645

Please sign in to comment.