diff --git a/arch/arm/core/fiber_abort.c b/arch/arm/core/fiber_abort.c index 705e572dabe..e80c9be3e99 100644 --- a/arch/arm/core/fiber_abort.c +++ b/arch/arm/core/fiber_abort.c @@ -52,7 +52,7 @@ void fiber_abort(void) { - _thread_exit(_nanokernel.current); + _thread_monitor_exit(_nanokernel.current); if (_ScbIsInThreadMode()) { _nano_fiber_swap(); } else { diff --git a/kernel/microkernel/k_task.c b/kernel/microkernel/k_task.c index f5e968d4f1a..f7f0c709cd2 100644 --- a/kernel/microkernel/k_task.c +++ b/kernel/microkernel/k_task.c @@ -252,7 +252,7 @@ static void abort_task(struct k_task *X) /* Do normal thread exit cleanup */ - _thread_exit((struct tcs *)X->workspace); + _thread_monitor_exit((struct tcs *)X->workspace); /* Set TF_TERM and TF_STOP state flags */ diff --git a/kernel/nanokernel/include/nano_internal.h b/kernel/nanokernel/include/nano_internal.h index 6a5f7ce53fb..c81d67c48f9 100644 --- a/kernel/nanokernel/include/nano_internal.h +++ b/kernel/nanokernel/include/nano_internal.h @@ -83,9 +83,9 @@ extern void _thread_essential_clear(void); /* clean up when a thread is aborted */ #if defined(CONFIG_THREAD_MONITOR) -extern void _thread_exit(struct tcs *tcs); +extern void _thread_monitor_exit(struct tcs *tcs); #else -#define _thread_exit(tcs) \ +#define _thread_monitor_exit(tcs) \ do {/* nothing */ \ } while (0) #endif /* CONFIG_THREAD_MONITOR */ diff --git a/kernel/nanokernel/nano_context.c b/kernel/nanokernel/nano_context.c index 7050179854c..6088cba54be 100644 --- a/kernel/nanokernel/nano_context.c +++ b/kernel/nanokernel/nano_context.c @@ -146,28 +146,16 @@ void *sys_thread_custom_data_get(void) #endif /* CONFIG_THREAD_CUSTOM_DATA */ #if defined(CONFIG_THREAD_MONITOR) -/** +/* + * Remove a thread from the kernel's list of active threads. * - * @brief Thread exit routine - * - * This function is invoked when the specified thread is aborted, either - * normally or abnormally. It is called for the termination of any thread, - * (fibers and tasks). - * - * This routine must be invoked either from a fiber or from a task with - * interrupts locked to guarantee that the list of threads does not change in - * mid-operation. It cannot be called from ISR context. - * - * @return N/A + * On entry the current thread must be in a non-preemptible state to ensure + * the list of threads does not change in mid-operation. (That is, it must + * be a fiber or interrupts must be locked.) This routine cannot be called + * from an ISR context. */ -void _thread_exit(struct tcs *thread) +void _thread_monitor_exit(struct tcs *thread) { - /* - * Remove thread from the list of threads. This singly linked list of - * threads maintains ALL the threads in the system: both tasks and - * fibers regardless of whether they are runnable. - */ - if (thread == _nanokernel.threads) { _nanokernel.threads = _nanokernel.threads->next_thread; } else { diff --git a/kernel/nanokernel/nano_fiber.c b/kernel/nanokernel/nano_fiber.c index cfb2f84629d..ff458447d2e 100644 --- a/kernel/nanokernel/nano_fiber.c +++ b/kernel/nanokernel/nano_fiber.c @@ -172,7 +172,7 @@ FUNC_NORETURN void fiber_abort(void) { /* Do normal thread exit cleanup, then give up CPU control */ - _thread_exit(_nanokernel.current); + _thread_monitor_exit(_nanokernel.current); _nano_fiber_swap(); } #endif @@ -214,7 +214,7 @@ void fiber_delayed_start_cancel(nano_thread_id_t handle) int key = irq_lock(); _nano_timeout_abort(cancelled_tcs); - _thread_exit(cancelled_tcs); + _thread_monitor_exit(cancelled_tcs); irq_unlock(key); } diff --git a/kernel/unified/include/nano_internal.h b/kernel/unified/include/nano_internal.h index 94460645274..e2a8f65a057 100644 --- a/kernel/unified/include/nano_internal.h +++ b/kernel/unified/include/nano_internal.h @@ -75,9 +75,9 @@ extern void _thread_essential_clear(void); /* clean up when a thread is aborted */ #if defined(CONFIG_THREAD_MONITOR) -extern void _thread_exit(struct tcs *tcs); +extern void _thread_monitor_exit(struct tcs *tcs); #else -#define _thread_exit(tcs) \ +#define _thread_monitor_exit(tcs) \ do {/* nothing */ \ } while (0) #endif /* CONFIG_THREAD_MONITOR */ diff --git a/kernel/unified/thread.c b/kernel/unified/thread.c index ed2c7a29384..0aa23b43c43 100644 --- a/kernel/unified/thread.c +++ b/kernel/unified/thread.c @@ -165,28 +165,16 @@ void *k_thread_custom_data_get(void) #endif /* CONFIG_THREAD_CUSTOM_DATA */ #if defined(CONFIG_THREAD_MONITOR) -/** +/* + * Remove a thread from the kernel's list of active threads. * - * @brief Thread exit routine - * - * This function is invoked when the specified thread is aborted, either - * normally or abnormally. It is called for the termination of any thread, - * (fibers and tasks). - * - * This routine must be invoked either from a fiber or from a task with - * interrupts locked to guarantee that the list of threads does not change in - * mid-operation. It cannot be called from ISR context. - * - * @return N/A + * On entry the current thread must be in a non-preemptible state to ensure + * the list of threads does not change in mid-operation. (That is, it must + * be non-preemptible or have locked the scheduler, or interrupts must be + * locked.) This routine cannot be called from an ISR context. */ -void _thread_exit(struct k_thread *thread) +void _thread_monitor_exit(struct k_thread *thread) { - /* - * Remove thread from the list of threads. This singly linked list of - * threads maintains ALL the threads in the system: both tasks and - * fibers regardless of whether they are runnable. - */ - if (thread == _nanokernel.threads) { _nanokernel.threads = _nanokernel.threads->next_thread; } else { @@ -308,7 +296,7 @@ int k_thread_cancel(k_tid_t tid) } _abort_thread_timeout(thread); - _thread_exit(thread); + _thread_monitor_exit(thread); irq_unlock(key);