diff options
author | H. Peter Anvin <hpa@zytor.com> | 2011-04-30 12:21:57 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2011-04-30 12:21:57 -0700 |
commit | da6d596aae0ebd3d4f6042ae361812242981a46e (patch) | |
tree | 25594131e17a65fa61738453827c837bf67b06d6 | |
parent | c69a11a0e4e232965845b8fa3e059f10e6715ef8 (diff) | |
download | syslinux-da6d596aae0ebd3d4f6042ae361812242981a46e.tar.gz |
thread: simplify the scheduler
need_schedule was no longer used by anything else, and schedule_lock
only verified if we were being called from inside sched_hook_func().
Make the localness of this data explicit.
While we're at it, call kaboom if we ever find ourselves without a
runnable thread (which should not be possible, as the idle thread is
not allowed to block.)
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | core/include/thread.h | 2 | ||||
-rw-r--r-- | core/thread/schedule.c | 23 |
2 files changed, 12 insertions, 13 deletions
diff --git a/core/include/thread.h b/core/include/thread.h index 44084ff3..5852df21 100644 --- a/core/include/thread.h +++ b/core/include/thread.h @@ -48,8 +48,6 @@ struct thread { int prio; }; -extern int __schedule_lock; -extern bool __need_schedule; extern void (*sched_hook_func)(void); void __thread_process_timeouts(void); diff --git a/core/thread/schedule.c b/core/thread/schedule.c index 674245ab..cf25f251 100644 --- a/core/thread/schedule.c +++ b/core/thread/schedule.c @@ -1,8 +1,6 @@ #include <sys/cpu.h> #include "thread.h" -int __schedule_lock; -bool __need_schedule; void (*sched_hook_func)(void); /* @@ -10,32 +8,32 @@ void (*sched_hook_func)(void); */ void __schedule(void) { + static bool in_sched_hook; struct thread *curr = current(); struct thread *st, *nt, *best; - if (__schedule_lock) { - __need_schedule = true; + /* + * Are we called from inside sched_hook_func()? If so we'll + * schedule anyway on the way out. + */ + if (in_sched_hook) return; - } /* Possibly update the information on which we make * scheduling decisions. */ if (sched_hook_func) { - __schedule_lock++; + in_sched_hook = true; sched_hook_func(); - __schedule_lock--; + in_sched_hook = false; } - __need_schedule = false; - - best = NULL; - /* * The unusual form of this walk is because we have to start with * the thread *following* curr, and curr may not actually be part * of the list anymore (in the case of __exit_thread). */ + best = NULL; nt = st = container_of(curr->list.next, struct thread, list); do { if (!nt->blocked) @@ -44,6 +42,9 @@ void __schedule(void) nt = container_of(nt->list.next, struct thread, list); } while (nt != st); + if (!best) + kaboom(); /* No runnable thread */ + if (best != curr) __switch_to(best); } |