VSF Documented
semaphore.h
Go to the documentation of this file.
1// __VSF_LINUX_SEMAPHORE_H__ is used in <semaphore.h>
2#ifndef __VSF_LINUX_KERNEL_SEMAPHORE_H__
3#define __VSF_LINUX_KERNEL_SEMAPHORE_H__
4
5#include <kernel/vsf_kernel.h>
6
7// for vsf_linux_trigger_t
9
13
14static inline void sema_init(struct semaphore *sem, int val)
15{
16 VSF_LINUX_ASSERT(val <= 0xFFFF);
17 vsf_eda_sync_init(&sem->trigger.use_as__vsf_trig_t, (uint_fast16_t)val, (uint_fast16_t)val);
18#if VSF_LINUX_CFG_SUPPORT_SIG == ENABLED
20 sem->trigger.pending_process = NULL;
21#endif
22}
23
24static inline int down_interruptible(struct semaphore *sem)
25{
27 return vsf_linux_trigger_pend(&sem->trigger, -1);
28}
29
30static inline void down(struct semaphore *sem)
31{
32 __vsf_thread_wait_for_sync(&sem->trigger.use_as__vsf_trig_t, -1);
33}
34
35static inline int down_trylock(struct semaphore *sem)
36{
37 // VSF_ERR_NONE = 0, VSF_ERR_NOT_READY = 1, match return value of down_trylock
38 return vsf_eda_sync_decrease(&sem->trigger.use_as__vsf_trig_t, 0);
39}
40
41static inline void up(struct semaphore *sem)
42{
43 vsf_eda_sync_increase(&sem->trigger.use_as__vsf_trig_t);
44}
45
46#endif
Definition vsf_linux.h:160
__le16 timeout
Definition ieee80211.h:94
#define NULL
Definition lvgl.h:26
unsigned short uint_fast16_t
Definition stdint.h:25
Definition semaphore.h:10
vsf_linux_trigger_t trigger
Definition semaphore.h:11
vsf_err_t vsf_eda_sync_init(vsf_sync_t *pthis, uint_fast16_t cur_value, uint_fast16_t max_value)
Initialize a sync object, the base of semaphore, mutex, trigger etc.
vsf_err_t vsf_eda_sync_increase(vsf_sync_t *pthis)
Increase a sync object, waking up the pending tasks if any.
vsf_err_t vsf_eda_sync_decrease(vsf_sync_t *pthis, vsf_timeout_tick_t timeout)
Decrease a sync object, pending if the resource is not available.
VSF_KERNEL_TIMEOUT_TICK_T vsf_timeout_tick_t
Timeout type in system timer ticks: negative means wait forever, 0 means non-blocking try,...
Definition vsf_eda.h:1491
int vsf_linux_trigger_pend(vsf_linux_trigger_t *trig, vsf_timeout_tick_t timeout)
Definition vsf_linux.c:725
#define VSF_LINUX_ASSERT
Definition vsf_linux_cfg.h:31
#define vsf_dlist_init_node( __host_type, __member, __item_ptr)
Definition vsf_list.h:717
vsf_sync_reason_t __vsf_thread_wait_for_sync(vsf_sync_t *sync, vsf_timeout_tick_t time_out)
Wait for a sync object (semaphore, trigger or mutex) inside a thread.
Definition vsf_thread.c:832
Generated from commit: vsfteam/vsf@a5104db