Skip to content

Commit 623d8fa

Browse files
TaiJuWuhenrikbrixandersen
authored andcommitted
kernel: cleanup thread state checks and nunecessary CONFIG check
The commit replaces negative thread state checks with a new, more descriptivepositive check. The expression `!z_is_thread_prevented_from_running()` is updated to `z_is_thread_ready()` where appropriate, making the code's intent clearer. Removes a redundant `IS_ENABLED(CONFIG_SMP)`, they are included #ifdef. Finally, this patch add the missing `#endif` directive. Signed-off-by: TaiJu Wu <[email protected]>
1 parent e069ce2 commit 623d8fa

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

kernel/sched.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static ALWAYS_INLINE struct k_thread *next_up(void)
172172
struct k_thread *mirqp = _current_cpu->metairq_preempted;
173173

174174
if (mirqp != NULL && (thread == NULL || !thread_is_metairq(thread))) {
175-
if (!z_is_thread_prevented_from_running(mirqp)) {
175+
if (z_is_thread_ready(mirqp)) {
176176
thread = mirqp;
177177
} else {
178178
_current_cpu->metairq_preempted = NULL;
@@ -204,7 +204,7 @@ static ALWAYS_INLINE struct k_thread *next_up(void)
204204
* queue such that we don't want to re-add it".
205205
*/
206206
bool queued = z_is_thread_queued(_current);
207-
bool active = !z_is_thread_prevented_from_running(_current);
207+
bool active = z_is_thread_ready(_current);
208208

209209
if (thread == NULL) {
210210
thread = _current_cpu->idle_thread;
@@ -409,8 +409,8 @@ static ALWAYS_INLINE void z_thread_halt(struct k_thread *thread, k_spinlock_key_
409409
arch_sched_directed_ipi(IPI_CPU_MASK(cpu->id));
410410
#else
411411
arch_sched_broadcast_ipi();
412-
#endif
413-
#endif
412+
#endif /* CONFIG_ARCH_HAS_DIRECTED_IPIS */
413+
#endif /* CONFIG_SMP && CONFIG_SCHED_IPI_SUPPORTED */
414414
if (arch_is_in_isr()) {
415415
thread_halt_spin(thread, key);
416416
} else {
@@ -856,10 +856,7 @@ void *z_get_next_switch_handle(void *interrupted)
856856

857857
K_SPINLOCK(&_sched_spinlock) {
858858
struct k_thread *old_thread = _current, *new_thread;
859-
860-
if (IS_ENABLED(CONFIG_SMP)) {
861-
old_thread->switch_handle = NULL;
862-
}
859+
old_thread->switch_handle = NULL;
863860
new_thread = next_up();
864861

865862
z_sched_usage_switch(new_thread);
@@ -907,10 +904,8 @@ void *z_get_next_switch_handle(void *interrupted)
907904
}
908905
old_thread->switch_handle = interrupted;
909906
ret = new_thread->switch_handle;
910-
if (IS_ENABLED(CONFIG_SMP)) {
911-
/* Active threads MUST have a null here */
912-
new_thread->switch_handle = NULL;
913-
}
907+
/* Active threads MUST have a null here */
908+
new_thread->switch_handle = NULL;
914909
}
915910
signal_pending_ipi();
916911
return ret;

0 commit comments

Comments
 (0)