1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

pkg/mynewt-core: fix semaphore

This commit is contained in:
Francisco Molina 2021-12-13 14:00:08 +01:00
parent a0ec3a0e02
commit d61256d8f2
2 changed files with 13 additions and 2 deletions

View File

@ -18,6 +18,7 @@
*/
#include <stdio.h>
#include <errno.h>
#include "irq.h"
#include "os/os_sem.h"
@ -31,11 +32,19 @@ os_error_t os_sem_init(struct os_sem *sem, uint16_t tokens)
os_error_t os_sem_release(struct os_sem *sem)
{
int ret = sema_post(&sem->sema);
return (ret) ? OS_ERROR : OS_OK;
}
os_error_t os_sem_pend(struct os_sem *sem, os_time_t timeout)
{
int ret = sema_wait_timed_ztimer(&sem->sema, ZTIMER_MSEC, timeout);
return (ret) ? OS_ERROR : OS_OK;
int ret;
if (timeout == OS_TIMEOUT_NEVER) {
ret = sema_wait(&sem->sema);
}
else {
ret = sema_wait_timed_ztimer(&sem->sema, ZTIMER_MSEC, timeout);
}
return ret == 0 ? OS_OK : ret == -ETIMEDOUT ? OS_TIMEOUT: OS_ERROR;
}

View File

@ -22,6 +22,8 @@
#include <stdint.h>
#include "dpl_types.h"
#include "dpl_error.h"
#include "os/os_sem.h"
#ifdef __cplusplus