git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7012 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-03-17 15:30:43 +00:00
parent 0f00c4fff9
commit 6e1d8b671a
+18 -21
View File
@@ -1,28 +1,25 @@
/* scheduler.c /* The thread scheduler */
*
* The scheduler code
*
*/
/* /*
** Copyright 2002-2004, The OpenBeOS Team. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
**
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
** Distributed under the terms of the NewOS License. ** Distributed under the terms of the NewOS License.
*/ */
#include <OS.h> #include <OS.h>
#include <kernel.h>
#include <thread.h> #include <thread.h>
#include <thread_types.h>
#include <timer.h> #include <timer.h>
#include <int.h> #include <int.h>
#include <smp.h> #include <smp.h>
#include <cpu.h> #include <cpu.h>
#include <khash.h> #include <khash.h>
#include <Errors.h>
#include <kerrors.h>
#define TRACE_SCHEDULER 0
#if TRACE_SCHEDULER //#define TRACE_SCHEDULER
#ifdef TRACE_SCHEDULER
# define TRACE(x) dprintf x # define TRACE(x) dprintf x
#else #else
# define TRACE(x) ; # define TRACE(x) ;
@@ -34,7 +31,7 @@ static int dump_run_queue(int argc, char **argv);
static int _rand(void); static int _rand(void);
// The run queue. Holds the threads ready to run ordered by priority. // The run queue. Holds the threads ready to run ordered by priority.
static struct thread_queue gRunQueue = {NULL, NULL}; static struct thread_queue sRunQueue = {NULL, NULL};
static int static int
@@ -55,7 +52,7 @@ dump_run_queue(int argc, char **argv)
{ {
struct thread *thread; struct thread *thread;
thread = gRunQueue.head; thread = sRunQueue.head;
if (!thread) if (!thread)
dprintf("Run queue is empty!\n"); dprintf("Run queue is empty!\n");
else { else {
@@ -84,17 +81,17 @@ scheduler_enqueue_in_run_queue(struct thread *thread)
if (thread->priority < B_MIN_PRIORITY) if (thread->priority < B_MIN_PRIORITY)
thread->priority = B_MIN_PRIORITY; thread->priority = B_MIN_PRIORITY;
for (curr = gRunQueue.head, prev = NULL; curr && (curr->priority >= thread->priority); curr = curr->queue_next) { for (curr = sRunQueue.head, prev = NULL; curr && (curr->priority >= thread->priority); curr = curr->queue_next) {
if (prev) if (prev)
prev = prev->queue_next; prev = prev->queue_next;
else else
prev = gRunQueue.head; prev = sRunQueue.head;
} }
thread->queue_next = curr; thread->queue_next = curr;
if (prev) if (prev)
prev->queue_next = thread; prev->queue_next = thread;
else else
gRunQueue.head = thread; sRunQueue.head = thread;
} }
@@ -108,11 +105,11 @@ scheduler_remove_from_run_queue(struct thread *thread)
struct thread *item, *prev; struct thread *item, *prev;
// find thread in run queue // find thread in run queue
for (item = gRunQueue.head, prev = NULL; item && item != thread; item = item->queue_next) { for (item = sRunQueue.head, prev = NULL; item && item != thread; item = item->queue_next) {
if (prev) if (prev)
prev = prev->queue_next; prev = prev->queue_next;
else else
prev = gRunQueue.head; prev = sRunQueue.head;
} }
ASSERT(item == thread); ASSERT(item == thread);
@@ -120,7 +117,7 @@ scheduler_remove_from_run_queue(struct thread *thread)
if (prev) if (prev)
prev->queue_next = item->queue_next; prev->queue_next = item->queue_next;
else else
gRunQueue.head = item->queue_next; sRunQueue.head = item->queue_next;
} }
@@ -188,7 +185,7 @@ scheduler_reschedule(void)
oldThread->state = oldThread->next_state; oldThread->state = oldThread->next_state;
// select next thread from the run queue // select next thread from the run queue
nextThread = gRunQueue.head; nextThread = sRunQueue.head;
prevThread = NULL; prevThread = NULL;
while (nextThread && (nextThread->priority > B_IDLE_PRIORITY)) { while (nextThread && (nextThread->priority > B_IDLE_PRIORITY)) {
// always extract real time threads // always extract real time threads
@@ -214,7 +211,7 @@ scheduler_reschedule(void)
if (prevThread) if (prevThread)
prevThread->queue_next = nextThread->queue_next; prevThread->queue_next = nextThread->queue_next;
else else
gRunQueue.head = nextThread->queue_next; sRunQueue.head = nextThread->queue_next;
nextThread->state = B_THREAD_RUNNING; nextThread->state = B_THREAD_RUNNING;
nextThread->next_state = B_THREAD_READY; nextThread->next_state = B_THREAD_READY;