2009-05-20 23:07:56 +03:00
|
|
|
#pypp 0
|
|
|
|
#include "kernel.hh"
|
|
|
|
|
2009-05-25 01:31:35 +03:00
|
|
|
void Thread::run ():
|
|
|
|
if flags & THREAD_FLAG_RUNNING:
|
|
|
|
return
|
|
|
|
flags |= THREAD_FLAG_RUNNING
|
|
|
|
if flags & THREAD_FLAG_WAITING:
|
|
|
|
return
|
|
|
|
schedule_next = first_scheduled
|
|
|
|
if schedule_next:
|
|
|
|
schedule_next->schedule_prev = this
|
|
|
|
first_scheduled = this
|
|
|
|
|
|
|
|
void Thread::unrun ():
|
|
|
|
if !(flags & THREAD_FLAG_RUNNING):
|
|
|
|
return
|
|
|
|
flags &= ~THREAD_FLAG_RUNNING
|
|
|
|
if !(flags & THREAD_FLAG_WAITING):
|
|
|
|
if current == this:
|
|
|
|
current = schedule_next
|
|
|
|
if schedule_prev:
|
|
|
|
schedule_prev->schedule_next = schedule_next
|
|
|
|
else:
|
|
|
|
first_scheduled = schedule_next
|
|
|
|
if schedule_next:
|
|
|
|
schedule_next->schedule_prev = schedule_prev
|
|
|
|
|
|
|
|
void Thread::wait ():
|
|
|
|
if flags & THREAD_FLAG_WAITING:
|
|
|
|
return
|
|
|
|
if flags & THREAD_FLAG_RUNNING:
|
|
|
|
unrun ()
|
|
|
|
flags |= THREAD_FLAG_WAITING
|
|
|
|
|
|
|
|
void Thread::unwait ():
|
|
|
|
if !(flags & THREAD_FLAG_WAITING):
|
|
|
|
return
|
|
|
|
flags &= ~THREAD_FLAG_WAITING
|
|
|
|
if flags & THREAD_FLAG_RUNNING:
|
|
|
|
flags &= ~THREAD_FLAG_RUNNING
|
|
|
|
run ()
|
|
|
|
|
2009-05-20 23:07:56 +03:00
|
|
|
void schedule ():
|
2009-05-22 23:48:49 +03:00
|
|
|
Thread *old = current
|
2009-05-25 01:31:35 +03:00
|
|
|
if current:
|
|
|
|
current = current->schedule_next
|
2009-05-20 23:07:56 +03:00
|
|
|
if !current:
|
|
|
|
current = first_scheduled
|
2009-05-23 21:55:31 +03:00
|
|
|
if !current:
|
|
|
|
current = &idle
|