Skip to content

Commit 989a8a5

Browse files
kernel: sys_workq: add option to allow blocking sys_workq
Add option which allows calling blocking APIs from the system workqueue. This option is inherently unsafe, but users may want to do it anyway. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 17b7a82 commit 989a8a5

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/kernel/services/threads/workqueue.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ its queue until the handler function finishes executing.
110110
it do not depend on subsequent work items in the queue to unblock them.
111111

112112
Attempting to perform a blocking call will fail an assert if
113-
:kconfig:option:`CONFIG_ASSERT` is enabled.
113+
:kconfig:option:`CONFIG_ASSERT` is enabled, unless
114+
:kconfig:option:`CONFIG_SYS_WORKQUEUE_BLOCKING` is selected. Use at your
115+
own risk.
114116

115117
The single argument that is passed to a handler function can be ignored if it
116118
is not required. If the handler function requires additional information about

kernel/Kconfig

+9
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,15 @@ config SYSTEM_WORKQUEUE_NO_YIELD
600600
cooperative and a sequence of work items is expected to complete
601601
without yielding.
602602

603+
config SYSTEM_WORKQUEUE_BLOCKING
604+
bool "Select whether system work queue allows blocking calls"
605+
help
606+
By default, the system work queue disallows blocking calls, to
607+
prevent deadlocking the system work queue. This is ensured by
608+
asserting that no work item handler unreadyes the system work
609+
queue thread. Selecting this removes the assert. Note that this
610+
option only has an effect if CONFIG_ASSERT=y.
611+
603612
endmenu
604613

605614
menu "Barrier Operations"

kernel/sched.c

+2
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,9 @@ static inline void z_vrfy_k_thread_resume(k_tid_t thread)
523523

524524
static void unready_thread(struct k_thread *thread)
525525
{
526+
#ifndef CONFIG_SYSTEM_WORKQUEUE_BLOCKING
526527
__ASSERT_NO_MSG(!k_is_in_sys_work());
528+
#endif /* CONFIG_SYSTEM_WORKQUEUE_BLOCKING */
527529
if (z_is_thread_queued(thread)) {
528530
dequeue_thread(thread);
529531
}

0 commit comments

Comments
 (0)