kernel: Replace redundant switch_handle assignment with assertion
The switch_handle for the outgoing thread is expected to be NULL at the start of a context switch. The previous code performed a redundant assignment to NULL. This change replaces the assignment with an __ASSERT(). This makes the code more robust by explicitly enforcing this precondition, helping to catch potential scheduler bugs earlier. Also, the switch_handle pointer is used to check a thread's state during a context switch. For dummy threads, this pointer was left uninitialized, potentially holding a unexpected value. Set the handle to NULL during initialization to ensure these threads are handled safely and predictably. Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>
This commit is contained in:
@@ -861,7 +861,10 @@ void *z_get_next_switch_handle(void *interrupted)
|
||||
|
||||
K_SPINLOCK(&_sched_spinlock) {
|
||||
struct k_thread *old_thread = _current, *new_thread;
|
||||
old_thread->switch_handle = NULL;
|
||||
|
||||
__ASSERT(old_thread->switch_handle == NULL,
|
||||
"old thread handle should be null.");
|
||||
|
||||
new_thread = next_up();
|
||||
|
||||
z_sched_usage_switch(new_thread);
|
||||
|
||||
@@ -1213,6 +1213,10 @@ void z_dummy_thread_init(struct k_thread *dummy_thread)
|
||||
dummy_thread->resource_pool = NULL;
|
||||
#endif /* K_HEAP_MEM_POOL_SIZE */
|
||||
|
||||
#ifdef CONFIG_USE_SWITCH
|
||||
dummy_thread->switch_handle = NULL;
|
||||
#endif /* CONFIG_USE_SWITCH */
|
||||
|
||||
#ifdef CONFIG_TIMESLICE_PER_THREAD
|
||||
dummy_thread->base.slice_ticks = 0;
|
||||
#endif /* CONFIG_TIMESLICE_PER_THREAD */
|
||||
|
||||
Reference in New Issue
Block a user