From: Lawrence S. <ljs...@us...> - 2013-03-25 00:23:59
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 85d151011bf46a9d06faa3a6d24abea603b792c2 (commit) from c7c191ff6c8e884d17f6a536be53ed68a4553a0e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 85d151011bf46a9d06faa3a6d24abea603b792c2 Author: Lawrence Sebald <ljs...@us...> Date: Sun Mar 24 20:23:23 2013 -0400 Change how threads are swapped a little bit. ----------------------------------------------------------------------- Summary of changes: kernel/thread/thread.c | 31 +++++++++++++++++++++++-------- 1 files changed, 23 insertions(+), 8 deletions(-) diff --git a/kernel/thread/thread.c b/kernel/thread/thread.c index a808e43..4c10b7d 100644 --- a/kernel/thread/thread.c +++ b/kernel/thread/thread.c @@ -66,6 +66,9 @@ static semaphore_t thd_reap_sem; /* Number of threads active in the system. */ static uint32 thd_count = 0; +/* The idle task */ +static kthread_t *thd_idle_thd = NULL; + /*****************************************************************************/ /* Debug */ @@ -485,9 +488,9 @@ void thd_schedule(int front_of_line, uint64 now) { arch_exit(); } - /* Re-queue the last "current" thread onto the run queue if - it didn't die */ - if(!dontenq && thd_current->state == STATE_RUNNING) { + /* If the current thread is supposed to be in the front of the line, and it + did not die, re-enqueue it to the front of the line now. */ + if(front_of_line && !dontenq && thd_current->state == STATE_RUNNING) { thd_current->state = STATE_READY; thd_add_to_runnable(thd_current, front_of_line); } @@ -504,6 +507,18 @@ void thd_schedule(int front_of_line, uint64 now) { break; } + /* If we didn't already re-enqueue the thread and we are supposed to do so, + do it now. */ + if(!front_of_line && !dontenq && thd_current->state == STATE_RUNNING) { + thd_current->state = STATE_READY; + thd_add_to_runnable(thd_current, front_of_line); + + /* Make sure we have a thread, just in case we couldn't find anything + above. */ + if(thd == NULL || thd == thd_idle_thd) + thd = thd_current; + } + /* Didn't find one? Big problem here... */ if(thd == NULL) { thd_pslist(printf); @@ -812,7 +827,7 @@ int kthread_key_delete(kthread_key_t key) { /* Init */ int thd_init(int mode) { - kthread_t *idle, *kern, *reaper; + kthread_t *kern, *reaper; /* Make sure we're not already running */ if(thd_mode != THD_MODE_NONE) @@ -849,10 +864,10 @@ int thd_init(int mode) { /* Setup an idle task that is always ready to run, in case everyone else is blocked on something. */ - idle = thd_create(0, thd_idle_task, NULL); - strcpy(idle->label, "[idle]"); - thd_set_prio(idle, PRIO_MAX); - idle->state = STATE_READY; + thd_idle_thd = thd_create(0, thd_idle_task, NULL); + strcpy(thd_idle_thd->label, "[idle]"); + thd_set_prio(thd_idle_thd, PRIO_MAX); + thd_idle_thd->state = STATE_READY; /* Set up a thread to reap old zombies */ sem_init(&thd_reap_sem, 0); hooks/post-receive -- A pseudo Operating System for the Dreamcast. |