projects
/
pintos-anon
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2cd697c
)
Add idle thread.
author
Ben Pfaff
<blp@cs.stanford.edu>
Sun, 29 Aug 2004 21:54:04 +0000
(21:54 +0000)
committer
Ben Pfaff
<blp@cs.stanford.edu>
Sun, 29 Aug 2004 21:54:04 +0000
(21:54 +0000)
src/threads/thread.c
patch
|
blob
|
history
diff --git
a/src/threads/thread.c
b/src/threads/thread.c
index 636caac22e0733a7df85d8c1861a3eb4b9a1a0ca..be607cfbe2273c8e065bffb2f775bf4865e0a432 100644
(file)
--- a/
src/threads/thread.c
+++ b/
src/threads/thread.c
@@
-12,11
+12,28
@@
uint32_t thread_stack_ofs = offsetof (struct thread, stack);
static struct list run_queue;
uint32_t thread_stack_ofs = offsetof (struct thread, stack);
static struct list run_queue;
+static struct thread *idle_thread;
+
+static void
+idle (void *aux UNUSED)
+{
+ for (;;)
+ {
+ /* Wait for an interrupt. */
+ asm ("hlt");
+
+ /* Let someone else run. */
+ intr_disable ();
+ thread_sleep ();
+ intr_enable ();
+ }
+}
void
thread_init (void)
{
list_init (&run_queue);
void
thread_init (void)
{
list_init (&run_queue);
+ idle_thread = thread_create ("idle", idle, NULL);
}
struct thread_root_frame
}
struct thread_root_frame
@@
-166,14
+183,6
@@
find_next_to_run (void)
return list_entry (list_pop_front (&run_queue), struct thread, rq_elem);
}
return list_entry (list_pop_front (&run_queue), struct thread, rq_elem);
}
-static void
-idle (void)
-{
- static int idle = 0;
- if (idle++ == 0)
- printk ("idle\n");
-}
-
void
thread_destroy (struct thread *t)
{
void
thread_destroy (struct thread *t)
{
@@
-210,8
+219,9
@@
thread_schedule (void)
cur = thread_current ();
ASSERT (cur->status != THREAD_RUNNING);
cur = thread_current ();
ASSERT (cur->status != THREAD_RUNNING);
- while ((next = find_next_to_run ()) == NULL)
- idle ();
+ next = find_next_to_run ();
+ if (next == NULL)
+ next = idle_thread;
next->status = THREAD_RUNNING;
if (cur != next)
next->status = THREAD_RUNNING;
if (cur != next)