mirror of
git://projects.qi-hardware.com/iris.git
synced 2024-11-04 23:46:17 +02:00
56 lines
1.2 KiB
COBOL
56 lines
1.2 KiB
COBOL
#pypp 0
|
|
#include "kernel.hh"
|
|
|
|
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
|
|
// Try to receive a message from a Receiver immediately.
|
|
for Receiver *r = receivers; r; r = r->next_owned:
|
|
if r->try_deliver ():
|
|
break
|
|
|
|
void Thread::unwait ():
|
|
if !(flags & THREAD_FLAG_WAITING):
|
|
return
|
|
flags &= ~THREAD_FLAG_WAITING
|
|
if flags & THREAD_FLAG_RUNNING:
|
|
flags &= ~THREAD_FLAG_RUNNING
|
|
run ()
|
|
|
|
void schedule ():
|
|
Thread *old = current
|
|
if current:
|
|
current = current->schedule_next
|
|
if !current:
|
|
current = first_scheduled
|
|
if !current:
|
|
current = &idle
|