2020-08-24 00:39:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Intel Corporation.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-06 17:04:23 +08:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/kernel_structs.h>
|
|
|
|
#include <zephyr/toolchain.h>
|
2020-08-24 00:39:09 +08:00
|
|
|
#include <ksched.h>
|
2023-08-30 01:03:12 +08:00
|
|
|
#include <wait_q.h>
|
2023-09-27 06:46:01 +08:00
|
|
|
#include <zephyr/internal/syscall_handler.h>
|
kernel: Integrate object cores into kernel
Integrates object cores into the following kernel structures
sys_mem_blocks, k_mem_slab
_cpu, z_kernel
k_thread, k_timer
k_condvar, k_event, k_mutex, k_sem
k_mbox, k_msgq, k_pipe, k_fifo, k_lifo, k_stack
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-05-12 02:06:46 +08:00
|
|
|
#include <zephyr/init.h>
|
|
|
|
|
|
|
|
#ifdef CONFIG_OBJ_CORE_CONDVAR
|
|
|
|
static struct k_obj_type obj_type_condvar;
|
2024-03-08 19:00:10 +08:00
|
|
|
#endif /* CONFIG_OBJ_CORE_CONDVAR */
|
2020-08-24 00:39:09 +08:00
|
|
|
|
|
|
|
static struct k_spinlock lock;
|
|
|
|
|
|
|
|
int z_impl_k_condvar_init(struct k_condvar *condvar)
|
|
|
|
{
|
|
|
|
z_waitq_init(&condvar->wait_q);
|
2023-09-27 05:32:13 +08:00
|
|
|
k_object_init(condvar);
|
2021-03-26 17:37:05 +08:00
|
|
|
|
kernel: Integrate object cores into kernel
Integrates object cores into the following kernel structures
sys_mem_blocks, k_mem_slab
_cpu, z_kernel
k_thread, k_timer
k_condvar, k_event, k_mutex, k_sem
k_mbox, k_msgq, k_pipe, k_fifo, k_lifo, k_stack
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-05-12 02:06:46 +08:00
|
|
|
#ifdef CONFIG_OBJ_CORE_CONDVAR
|
|
|
|
k_obj_core_init_and_link(K_OBJ_CORE(condvar), &obj_type_condvar);
|
2024-03-08 19:00:10 +08:00
|
|
|
#endif /* CONFIG_OBJ_CORE_CONDVAR */
|
kernel: Integrate object cores into kernel
Integrates object cores into the following kernel structures
sys_mem_blocks, k_mem_slab
_cpu, z_kernel
k_thread, k_timer
k_condvar, k_event, k_mutex, k_sem
k_mbox, k_msgq, k_pipe, k_fifo, k_lifo, k_stack
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-05-12 02:06:46 +08:00
|
|
|
|
2021-03-26 17:37:05 +08:00
|
|
|
SYS_PORT_TRACING_OBJ_INIT(k_condvar, condvar, 0);
|
|
|
|
|
2020-08-24 00:39:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-28 00:30:45 +08:00
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
int z_vrfy_k_condvar_init(struct k_condvar *condvar)
|
|
|
|
{
|
2023-09-27 19:20:28 +08:00
|
|
|
K_OOPS(K_SYSCALL_OBJ_INIT(condvar, K_OBJ_CONDVAR));
|
2020-11-28 00:30:45 +08:00
|
|
|
return z_impl_k_condvar_init(condvar);
|
|
|
|
}
|
2024-01-24 17:35:04 +08:00
|
|
|
#include <zephyr/syscalls/k_condvar_init_mrsh.c>
|
2024-03-08 19:00:10 +08:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
2020-11-28 00:30:45 +08:00
|
|
|
|
2020-08-24 00:39:09 +08:00
|
|
|
int z_impl_k_condvar_signal(struct k_condvar *condvar)
|
|
|
|
{
|
|
|
|
k_spinlock_key_t key = k_spin_lock(&lock);
|
2021-03-26 17:37:05 +08:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_condvar, signal, condvar);
|
|
|
|
|
2020-08-24 00:39:09 +08:00
|
|
|
struct k_thread *thread = z_unpend_first_thread(&condvar->wait_q);
|
|
|
|
|
2024-10-10 06:36:48 +08:00
|
|
|
if (unlikely(thread != NULL)) {
|
2021-03-26 17:37:05 +08:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_condvar, signal, condvar, K_FOREVER);
|
|
|
|
|
2020-08-24 00:39:09 +08:00
|
|
|
arch_thread_return_value_set(thread, 0);
|
|
|
|
z_ready_thread(thread);
|
|
|
|
z_reschedule(&lock, key);
|
|
|
|
} else {
|
|
|
|
k_spin_unlock(&lock, key);
|
|
|
|
}
|
2021-03-26 17:37:05 +08:00
|
|
|
|
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_condvar, signal, condvar, 0);
|
|
|
|
|
2020-08-24 00:39:09 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-28 00:30:45 +08:00
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
int z_vrfy_k_condvar_signal(struct k_condvar *condvar)
|
|
|
|
{
|
2023-09-27 19:20:28 +08:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(condvar, K_OBJ_CONDVAR));
|
2020-11-28 00:30:45 +08:00
|
|
|
return z_impl_k_condvar_signal(condvar);
|
|
|
|
}
|
2024-01-24 17:35:04 +08:00
|
|
|
#include <zephyr/syscalls/k_condvar_signal_mrsh.c>
|
2024-03-08 19:00:10 +08:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
2020-11-28 00:30:45 +08:00
|
|
|
|
2020-08-24 00:39:09 +08:00
|
|
|
int z_impl_k_condvar_broadcast(struct k_condvar *condvar)
|
|
|
|
{
|
|
|
|
struct k_thread *pending_thread;
|
|
|
|
k_spinlock_key_t key;
|
|
|
|
int woken = 0;
|
|
|
|
|
|
|
|
key = k_spin_lock(&lock);
|
|
|
|
|
2021-03-26 17:37:05 +08:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_condvar, broadcast, condvar);
|
|
|
|
|
2020-08-24 00:39:09 +08:00
|
|
|
/* wake up any threads that are waiting to write */
|
2024-05-02 20:02:20 +08:00
|
|
|
for (pending_thread = z_unpend_first_thread(&condvar->wait_q); pending_thread != NULL;
|
|
|
|
pending_thread = z_unpend_first_thread(&condvar->wait_q)) {
|
2021-03-03 05:22:52 +08:00
|
|
|
woken++;
|
2020-08-24 00:39:09 +08:00
|
|
|
arch_thread_return_value_set(pending_thread, 0);
|
|
|
|
z_ready_thread(pending_thread);
|
|
|
|
}
|
|
|
|
|
2021-03-26 17:37:05 +08:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_condvar, broadcast, condvar, woken);
|
|
|
|
|
2020-08-24 00:39:09 +08:00
|
|
|
z_reschedule(&lock, key);
|
|
|
|
|
|
|
|
return woken;
|
|
|
|
}
|
2020-11-28 00:30:45 +08:00
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
int z_vrfy_k_condvar_broadcast(struct k_condvar *condvar)
|
|
|
|
{
|
2023-09-27 19:20:28 +08:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(condvar, K_OBJ_CONDVAR));
|
2020-11-28 00:30:45 +08:00
|
|
|
return z_impl_k_condvar_broadcast(condvar);
|
|
|
|
}
|
2024-01-24 17:35:04 +08:00
|
|
|
#include <zephyr/syscalls/k_condvar_broadcast_mrsh.c>
|
2024-03-08 19:00:10 +08:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
2020-08-24 00:39:09 +08:00
|
|
|
|
|
|
|
int z_impl_k_condvar_wait(struct k_condvar *condvar, struct k_mutex *mutex,
|
|
|
|
k_timeout_t timeout)
|
|
|
|
{
|
|
|
|
k_spinlock_key_t key;
|
|
|
|
int ret;
|
|
|
|
|
2021-03-26 17:37:05 +08:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_condvar, wait, condvar);
|
|
|
|
|
2020-08-24 00:39:09 +08:00
|
|
|
key = k_spin_lock(&lock);
|
|
|
|
k_mutex_unlock(mutex);
|
|
|
|
|
|
|
|
ret = z_pend_curr(&lock, key, &condvar->wait_q, timeout);
|
|
|
|
k_mutex_lock(mutex, K_FOREVER);
|
|
|
|
|
2021-03-26 17:37:05 +08:00
|
|
|
SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_condvar, wait, condvar, ret);
|
|
|
|
|
2020-08-24 00:39:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2020-11-28 00:30:45 +08:00
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
int z_vrfy_k_condvar_wait(struct k_condvar *condvar, struct k_mutex *mutex,
|
|
|
|
k_timeout_t timeout)
|
|
|
|
{
|
2023-09-27 19:20:28 +08:00
|
|
|
K_OOPS(K_SYSCALL_OBJ(condvar, K_OBJ_CONDVAR));
|
|
|
|
K_OOPS(K_SYSCALL_OBJ(mutex, K_OBJ_MUTEX));
|
2020-11-28 00:30:45 +08:00
|
|
|
return z_impl_k_condvar_wait(condvar, mutex, timeout);
|
|
|
|
}
|
2024-01-24 17:35:04 +08:00
|
|
|
#include <zephyr/syscalls/k_condvar_wait_mrsh.c>
|
2024-03-08 19:00:10 +08:00
|
|
|
#endif /* CONFIG_USERSPACE */
|
kernel: Integrate object cores into kernel
Integrates object cores into the following kernel structures
sys_mem_blocks, k_mem_slab
_cpu, z_kernel
k_thread, k_timer
k_condvar, k_event, k_mutex, k_sem
k_mbox, k_msgq, k_pipe, k_fifo, k_lifo, k_stack
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-05-12 02:06:46 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_OBJ_CORE_CONDVAR
|
|
|
|
static int init_condvar_obj_core_list(void)
|
|
|
|
{
|
|
|
|
/* Initialize condvar object type */
|
|
|
|
|
|
|
|
z_obj_type_init(&obj_type_condvar, K_OBJ_TYPE_CONDVAR_ID,
|
|
|
|
offsetof(struct k_condvar, obj_core));
|
|
|
|
|
|
|
|
/* Initialize and link statically defined condvars */
|
|
|
|
|
|
|
|
STRUCT_SECTION_FOREACH(k_condvar, condvar) {
|
|
|
|
k_obj_core_init_and_link(K_OBJ_CORE(condvar),
|
|
|
|
&obj_type_condvar);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_INIT(init_condvar_obj_core_list, PRE_KERNEL_1,
|
|
|
|
CONFIG_KERNEL_INIT_PRIORITY_OBJECTS);
|
2024-03-08 19:00:10 +08:00
|
|
|
#endif /* CONFIG_OBJ_CORE_CONDVAR */
|