#define STACK_SIZE (1024 * 1024)
-static struct thread *current, *main_thread;
+static struct thread *main_thread;
static void *stack_allocate(size_t size)
{
struct thread *old, *next;
DBG();
- old = current;
+ old = thread_current();
model->scheduler->add_thread(old);
next = model->scheduler->next_thread();
- current = next;
DEBUG("(%d, %d)\n", old->index, next->index);
return thread_swap(old, next);
}
static void thread_wait_finish(void)
{
- struct thread *next;
+ struct thread *curr, *next;
DBG();
do {
- if (current)
- thread_dispose(current);
+ if ((curr = thread_current()))
+ thread_dispose(curr);
next = model->scheduler->next_thread();
- current = next;
} while (next && !thread_swap(main_thread, next));
}
struct thread *thread_current(void)
{
- return current;
+ return model->scheduler->get_current_thread();
}
int main()