[syslinux:lwip] thread: simplify the scheduler

syslinux-bot for H. Peter Anvin hpa at zytor.com
Sat Apr 30 14:15:23 PDT 2011


Commit-ID:  da6d596aae0ebd3d4f6042ae361812242981a46e
Gitweb:     http://syslinux.zytor.com/commit/da6d596aae0ebd3d4f6042ae361812242981a46e
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Sat, 30 Apr 2011 12:21:57 -0700
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Sat, 30 Apr 2011 12:21:57 -0700

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 at zytor.com>


---
 core/include/thread.h  |    2 --
 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 44084ff..5852df2 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 674245a..cf25f25 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);
 }



More information about the Syslinux-commits mailing list