FreeNOS
Scheduler.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <Log.h>
19#include "Kernel.h"
20#include "Scheduler.h"
21
23{
24 DEBUG("");
25}
26
28{
29 return m_queue.count();
30}
31
33{
34 if (proc->getState() != Process::Ready && !ignoreState)
35 {
36 ERROR("process ID " << proc->getID() << " not in Ready state");
37 return InvalidArgument;
38 }
39
40 m_queue.push(proc);
41 return Success;
42}
43
45{
46 if (proc->getState() == Process::Ready && !ignoreState)
47 {
48 ERROR("process ID " << proc->getID() << " is in Ready state");
49 return InvalidArgument;
50 }
51
53
54 // Traverse the Queue to remove the Process
55 for (Size i = 0; i < count; i++)
56 {
57 Process *p = m_queue.pop();
58
59 if (p == proc)
60 return Success;
61 else
62 m_queue.push(p);
63 }
64
65 FATAL("process ID " << proc->getID() << " is not in the schedule");
66 return InvalidArgument;
67}
68
70{
71 if (m_queue.count() > 0)
72 {
73 Process *p = m_queue.pop();
74 m_queue.push(p);
75
76 return p;
77 }
78
79 return (Process *) NULL;
80}
Represents a process which may run on the host.
Definition Process.h:45
@ Ready
Definition Process.h:68
State getState() const
Retrieves the current state.
Definition Process.cpp:80
ProcessID getID() const
Retrieve our ID number.
Definition Process.cpp:60
T & pop()
Remove item from the tail of the Queue.
Definition Queue.h:76
virtual Size count() const
Returns the number of items in the Queue.
Definition Queue.h:153
bool push(const T &item)
Add item to the head of the Queue.
Definition Queue.h:55
Queue< Process *, MAX_PROCS > m_queue
Contains processes ready to run.
Definition Scheduler.h:93
Result dequeue(Process *proc, bool ignoreState)
Remove a Process from the run schedule.
Definition Scheduler.cpp:44
Scheduler()
Constructor function.
Definition Scheduler.cpp:22
Process * select()
Select the next process to run.
Definition Scheduler.cpp:69
Size count() const
Get number of processes on the schedule.
Definition Scheduler.cpp:27
Result enqueue(Process *proc, bool ignoreState)
Add a Process to the run schedule.
Definition Scheduler.cpp:32
Result
Result code.
Definition Scheduler.h:44
@ InvalidArgument
Definition Scheduler.h:46
#define NULL
NULL means zero.
Definition Macros.h:39
#define ERROR(msg)
Output an error message.
Definition Log.h:61
#define FATAL(msg)
Output a critical message and terminate program immediatly.
Definition Log.h:50
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
#define DEBUG(msg)
Output a debug message to standard output.
Definition Log.h:89