Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel/sched: Fix preemption logic #8077

Merged
merged 1 commit into from
May 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,15 @@ int _is_t1_higher_prio_than_t2(struct k_thread *t1, struct k_thread *t2)

static int should_preempt(struct k_thread *th, int preempt_ok)
{
/* System initialization states can have dummy threads, never
* refuse to swap those
/* Preemption is OK if it's being explicitly allowed by
* software state (e.g. the thread called k_yield())
*/
if (!_current || _is_thread_dummy(_current)) {
return 1;
}

/* The idle threads can look "cooperative" if there are no
* preemptible priorities (this is sort of an API glitch).
* They must always be preemptible.
*/
if (_is_idle(_current)) {
if (preempt_ok) {
return 1;
}

/* Preemption is OK if it's being explicitly allowed */
if (preempt_ok) {
/* Or if we're pended/suspended/dummy (duh) */
if (!_current || _is_thread_prevented_from_running(_current)) {
return 1;
}

Expand All @@ -141,6 +133,14 @@ static int should_preempt(struct k_thread *th, int preempt_ok)
return 1;
}

/* The idle threads can look "cooperative" if there are no
* preemptible priorities (this is sort of an API glitch).
* They must always be preemptible.
*/
if (_is_idle(_current)) {
return 1;
}

return 0;
}

Expand Down