kernel: Add posix API for semaphore

Add semaphore posix APIs.

Signed-off-by: Punit Vara <punit.vara@intel.com>
This commit is contained in:
Punit Vara 2018-02-06 09:27:44 +05:30 committed by Anas Nashif
commit a74725f1d3
7 changed files with 210 additions and 1 deletions

View file

@ -157,7 +157,6 @@ static inline int pthread_condattr_destroy(pthread_condattr_t *att)
.sem = &name##_psem, \
}
/**
* @brief POSIX threading compatibility API
*

28
include/posix/semaphore.h Normal file
View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _POSIX_SEMAPHORE_H
#define _POSIX_SEMAPHORE_H
#ifdef __cplusplus
extern "C" {
#endif
#include "sys/types.h"
#include <time.h>
int sem_destroy(sem_t *semaphore);
int sem_getvalue(sem_t *semaphore, int *value);
int sem_init(sem_t *semaphore, int pshared, unsigned int value);
int sem_post(sem_t *semaphore);
int sem_timedwait(sem_t *semaphore, struct timespec *abstime);
int sem_trywait(sem_t *semaphore);
int sem_wait(sem_t *semaphore);
#ifdef __cplusplus
}
#endif
#endif /* POSIX_SEMAPHORE_H */

View file

@ -30,6 +30,9 @@ typedef struct pthread_attr_t {
typedef void *pthread_t;
/* Semaphore */
typedef struct k_sem sem_t;
/* Mutex */
typedef struct pthread_mutex {
struct k_sem *sem;