5611e92347
A k_futex is a lightweight mutual exclusion primitive designed to minimize kernel involvement. Uncontended operation relies only on atomic access to shared memory. k_futex structure lives in application memory. And when using futexes, the majority of the synchronization operations are performed in user mode. A user-mode thread employs the futex wait system call only when it is likely that the program has to block for a longer time until the condition becomes true. When the condition comes true, futex wake operation will be used to wake up one or more threads waiting on that futex. This patch implements two futex operations: k_futex_wait and k_futex_wake. For k_futex_wait, the comparison with the expected value, and starting to sleep are performed atomically to prevent lost wake-ups. If different context changed futex's value after the calling use-mode thread decided to block himself based on the old value, the comparison will help observing the value change and will not start to sleep. And for k_futex_wake, it will wake at most num_waiters of the waiters that are sleeping on that futex. But no guarantees are made on which threads are woken, that means scheduling priority is not taken into consideration. Fixes: #14493. Signed-off-by: Wentong Wu <wentong.wu@intel.com>
59 lines
1.3 KiB
CMake
59 lines
1.3 KiB
CMake
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
# kernel is a normal CMake library and not a zephyr_library because it
|
|
# should not be --whole-archive'd
|
|
add_library(kernel
|
|
device.c
|
|
errno.c
|
|
idle.c
|
|
init.c
|
|
mailbox.c
|
|
mem_slab.c
|
|
mempool.c
|
|
msg_q.c
|
|
mutex.c
|
|
pipes.c
|
|
queue.c
|
|
sched.c
|
|
sem.c
|
|
stack.c
|
|
system_work_q.c
|
|
thread.c
|
|
thread_abort.c
|
|
version.c
|
|
work_q.c
|
|
smp.c
|
|
)
|
|
|
|
# Kernel files has the macro __ZEPHYR_SUPERVISOR__ set so that it
|
|
# optimizes the code when userspace is enabled.
|
|
set_target_properties(
|
|
kernel
|
|
PROPERTIES
|
|
COMPILE_DEFINITIONS
|
|
__ZEPHYR_SUPERVISOR__
|
|
)
|
|
|
|
target_sources_ifdef(CONFIG_STACK_CANARIES kernel PRIVATE compiler_stack_protect.c)
|
|
target_sources_ifdef(CONFIG_SYS_CLOCK_EXISTS kernel PRIVATE timeout.c timer.c)
|
|
target_sources_ifdef(CONFIG_ATOMIC_OPERATIONS_C kernel PRIVATE atomic_c.c)
|
|
target_sources_if_kconfig( kernel PRIVATE poll.c)
|
|
|
|
# The last 2 files inside the target_sources_ifdef should be
|
|
# userspace_handler.c and userspace.c. If not the linker would complain.
|
|
# This order has to be maintained. Any new file should be placed
|
|
# above these 2 files.
|
|
target_sources_ifdef(
|
|
CONFIG_USERSPACE
|
|
kernel PRIVATE
|
|
futex.c
|
|
mem_domain.c
|
|
userspace_handler.c
|
|
userspace.c
|
|
)
|
|
|
|
|
|
add_dependencies(kernel ${OFFSETS_H_TARGET})
|
|
|
|
target_link_libraries(kernel zephyr_interface)
|