123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #ifndef ZEPHYR_INCLUDE_SYS_SEM_H_
- #define ZEPHYR_INCLUDE_SYS_SEM_H_
- #include <kernel.h>
- #include <sys/atomic.h>
- #include <zephyr/types.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- struct sys_sem {
- #ifdef CONFIG_USERSPACE
- struct k_futex futex;
- int limit;
- #else
- struct k_sem kernel_sem;
- #endif
- };
- #ifdef CONFIG_USERSPACE
- #define SYS_SEM_DEFINE(_name, _initial_count, _count_limit) \
- struct sys_sem _name = { \
- .futex = { _initial_count }, \
- .limit = _count_limit \
- }; \
- BUILD_ASSERT(((_count_limit) != 0) && \
- ((_initial_count) <= (_count_limit)))
- #else
- #define SYS_SEM_DEFINE(_name, _initial_count, _count_limit) \
- STRUCT_SECTION_ITERABLE_ALTERNATE(k_sem, sys_sem, _name) = { \
- .kernel_sem = Z_SEM_INITIALIZER(_name.kernel_sem, \
- _initial_count, _count_limit) \
- }; \
- BUILD_ASSERT(((_count_limit) != 0) && \
- ((_initial_count) <= (_count_limit)))
- #endif
- int sys_sem_init(struct sys_sem *sem, unsigned int initial_count,
- unsigned int limit);
- int sys_sem_give(struct sys_sem *sem);
- int sys_sem_take(struct sys_sem *sem, k_timeout_t timeout);
- unsigned int sys_sem_count_get(struct sys_sem *sem);
- #ifdef __cplusplus
- }
- #endif
- #endif
|