Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POSIX compatibility #2

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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