Lines Matching refs:sem
45 int z_impl_k_sem_init(struct k_sem *sem, unsigned int initial_count, in z_impl_k_sem_init() argument
52 SYS_PORT_TRACING_OBJ_FUNC(k_sem, init, sem, -EINVAL); in z_impl_k_sem_init()
57 sem->count = initial_count; in z_impl_k_sem_init()
58 sem->limit = limit; in z_impl_k_sem_init()
60 SYS_PORT_TRACING_OBJ_FUNC(k_sem, init, sem, 0); in z_impl_k_sem_init()
62 z_waitq_init(&sem->wait_q); in z_impl_k_sem_init()
64 sys_dlist_init(&sem->poll_events); in z_impl_k_sem_init()
66 k_object_init(sem); in z_impl_k_sem_init()
69 k_obj_core_init_and_link(K_OBJ_CORE(sem), &obj_type_sem); in z_impl_k_sem_init()
76 int z_vrfy_k_sem_init(struct k_sem *sem, unsigned int initial_count, in z_vrfy_k_sem_init() argument
79 K_OOPS(K_SYSCALL_OBJ_INIT(sem, K_OBJ_SEM)); in z_vrfy_k_sem_init()
80 return z_impl_k_sem_init(sem, initial_count, limit); in z_vrfy_k_sem_init()
85 static inline bool handle_poll_events(struct k_sem *sem) in handle_poll_events() argument
88 z_handle_obj_poll_events(&sem->poll_events, K_POLL_STATE_SEM_AVAILABLE); in handle_poll_events()
91 ARG_UNUSED(sem); in handle_poll_events()
96 void z_impl_k_sem_give(struct k_sem *sem) in z_impl_k_sem_give() argument
102 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_sem, give, sem); in z_impl_k_sem_give()
104 thread = z_unpend_first_thread(&sem->wait_q); in z_impl_k_sem_give()
110 sem->count += (sem->count != sem->limit) ? 1U : 0U; in z_impl_k_sem_give()
111 resched = handle_poll_events(sem); in z_impl_k_sem_give()
120 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_sem, give, sem); in z_impl_k_sem_give()
124 static inline void z_vrfy_k_sem_give(struct k_sem *sem) in z_vrfy_k_sem_give() argument
126 K_OOPS(K_SYSCALL_OBJ(sem, K_OBJ_SEM)); in z_vrfy_k_sem_give()
127 z_impl_k_sem_give(sem); in z_vrfy_k_sem_give()
132 int z_impl_k_sem_take(struct k_sem *sem, k_timeout_t timeout) in z_impl_k_sem_take() argument
141 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_sem, take, sem, timeout); in z_impl_k_sem_take()
143 if (likely(sem->count > 0U)) { in z_impl_k_sem_take()
144 sem->count--; in z_impl_k_sem_take()
156 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_sem, take, sem, timeout); in z_impl_k_sem_take()
158 ret = z_pend_curr(&lock, key, &sem->wait_q, timeout); in z_impl_k_sem_take()
161 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_sem, take, sem, timeout, ret); in z_impl_k_sem_take()
166 void z_impl_k_sem_reset(struct k_sem *sem) in z_impl_k_sem_reset() argument
172 thread = z_unpend_first_thread(&sem->wait_q); in z_impl_k_sem_reset()
179 sem->count = 0; in z_impl_k_sem_reset()
181 SYS_PORT_TRACING_OBJ_FUNC(k_sem, reset, sem); in z_impl_k_sem_reset()
183 handle_poll_events(sem); in z_impl_k_sem_reset()
189 static inline int z_vrfy_k_sem_take(struct k_sem *sem, k_timeout_t timeout) in z_vrfy_k_sem_take() argument
191 K_OOPS(K_SYSCALL_OBJ(sem, K_OBJ_SEM)); in z_vrfy_k_sem_take()
192 return z_impl_k_sem_take(sem, timeout); in z_vrfy_k_sem_take()
196 static inline void z_vrfy_k_sem_reset(struct k_sem *sem) in z_vrfy_k_sem_reset() argument
198 K_OOPS(K_SYSCALL_OBJ(sem, K_OBJ_SEM)); in z_vrfy_k_sem_reset()
199 z_impl_k_sem_reset(sem); in z_vrfy_k_sem_reset()
203 static inline unsigned int z_vrfy_k_sem_count_get(struct k_sem *sem) in z_vrfy_k_sem_count_get() argument
205 K_OOPS(K_SYSCALL_OBJ(sem, K_OBJ_SEM)); in z_vrfy_k_sem_count_get()
206 return z_impl_k_sem_count_get(sem); in z_vrfy_k_sem_count_get()
222 STRUCT_SECTION_FOREACH(k_sem, sem) { in init_sem_obj_core_list()
223 k_obj_core_init_and_link(K_OBJ_CORE(sem), &obj_type_sem); in init_sem_obj_core_list()