1
0
mirror of git://projects.qi-hardware.com/iris.git synced 2024-07-01 03:36:43 +03:00
iris/schedule.ccp

73 lines
2.0 KiB
Plaintext
Raw Normal View History

2009-05-20 23:07:56 +03:00
#pypp 0
2009-06-01 15:26:42 +03:00
// Iris: micro-kernel for a capability-based operating system.
// schedule.ccp: Thread scheduling.
// Copyright 2009 Bas Wijnen <wijnen@debian.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2009-05-20 23:07:56 +03:00
#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
2009-06-01 02:12:54 +03:00
// Try to receive a message from a Receiver immediately.
for Receiver *r = receivers; r; r = r->next_owned:
if r->try_deliver ():
break
2009-05-25 01:31:35 +03:00
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