18#include <FreeNOS/System.h>
27 , m_interruptNotifyList(256)
47 const bool readyToRun,
48 const bool privileged)
62 ERROR(
"failed to allocate Process");
71 ERROR(
"failed to initialize Process: result = " << (
int) result);
110 for (
Size i = 0; i < size; i++)
120 ": result = " << (
int) result);
126 FATAL(
"failed to enqueue() PID " <<
m_procs[i]->getID() <<
127 ": result = " << (
int) r);
143 FATAL(
"failed to dequeue PID " << proc->
getID());
148 assert(countRemoved <= 1U);
169 FATAL(
"no process found to run!");
173 for (
Size i = 0; i < sleepTimerCount; i++)
213 FATAL(
"failed to dequeue PID " << proc->
getID());
236 ERROR(
"failed to stop PID " << proc->
getID() <<
": result = " << (
int) result);
255 ERROR(
"failed to resume PID " << proc->
getID() <<
": result = " << (
int) result);
266 ERROR(
"cannot reset current Process");
299 ": result: " << (
uint) result);
319 ERROR(
"failed to wakeup process ID " << proc->
getID() <<
320 ": result: " << (
uint) result);
338 ERROR(
"failed to raise event in process ID " << proc->
getID() <<
339 ": result: " << (
uint) result);
383 event.number = vector;
389 ERROR(
"failed to raise InterruptEvent for IRQ #" << vector <<
390 " on Process ID " << i.current()->getID());
403 ERROR(
"process ID " << proc->
getID() <<
" not added to Scheduler");
408 assert(countRemoved <= 1U);
418 ERROR(
"process ID " << proc->
getID() <<
" not removed from Scheduler");
virtual T * get(const Size position) const
Returns the item at the given position.
virtual bool insertAt(const Size position, T *item)
Inserts the given item at the given position.
virtual bool insert(Size &position, T *item)
Adds the given item, if possible.
virtual Size size() const
Size of the Index.
virtual bool remove(const Size position)
Removes the item at the given position.
Timer * getTimer()
Get Timer.
virtual bool hasCurrent() const
Check if there is a current item on the List.
Simple linked list template class.
virtual int remove(T t)
Remove all items which are equal to the given item.
Describes virtual memory map layout.
Result unregisterInterruptNotify(Process *proc)
Remove all interrupt notifications for a Process.
Result reset(Process *proc, const Address entry)
Restart execution of a Process at the given entry point.
Result registerInterruptNotify(Process *proc, const u32 vector)
Register an interrupt notification for a Process.
ProcessManager()
Constructor function.
void setIdle(Process *proc)
Set the idle process.
Result resume(Process *proc)
Resume scheduling of the given Process.
Result sleep(const Timer::Info *timer=0, const bool ignoreWakeups=false)
Let current Process sleep until a timer expires or wakeup occurs.
Result dequeueProcess(Process *proc, const bool ignoreState=false) const
Remove the given process on the Schedule queue.
Scheduler * m_scheduler
Object which selects processes to run.
Result wait(Process *proc)
Let current Process wait for another Process to terminate.
Process * create(const Address entry, const MemoryMap &map, const bool readyToRun=false, const bool privileged=false)
Create a new Process.
Process * m_idle
Idle process.
Result wakeup(Process *proc)
Take Process out of Sleep state and mark ready for execution.
void remove(Process *proc, const uint exitStatus=0)
Remove a Process.
Vector< List< Process * > * > m_interruptNotifyList
Interrupt notification list.
Result raiseEvent(Process *proc, const struct ProcessEvent *event)
Raise kernel event for a Process.
Queue< Process *, MAX_PROCS > m_sleepTimerQueue
Queue with sleeping processes waiting for a Timer to expire.
Result stop(Process *proc)
Remove given Process from the Scheduler.
Result schedule()
Schedule next process to run.
Process * m_current
Currently executing process.
Result enqueueProcess(Process *proc, const bool ignoreState=false)
Place the given process on the Schedule queue.
Result interruptNotify(const u32 vector)
Raise interrupt notifications for a interrupt vector.
virtual ~ProcessManager()
Destructor function.
Process * get(const ProcessID id)
Retrieve a Process by it's ID.
Process * current()
Current process running.
Index< Process, MAX_PROCS > m_procs
All known Processes.
Represents a process which may run on the host.
virtual void reset(const Address entry)=0
Restart execution at the given entry point.
const Timer::Info & getSleepTimer() const
Get sleep timer.
Result wait(ProcessID id)
Let Process wait for other Process to terminate.
State
Represents the execution state of the Process.
Result stop()
Stop execution of this process.
Result resume()
Resume execution when this process is stopped.
Result sleep(const Timer::Info *timer, bool ignoreWakeups)
Stops the process for executing until woken up.
State getState() const
Retrieves the current state.
virtual Result initialize()
Initialize the Process.
ProcessID getID() const
Retrieve our ID number.
void setParent(ProcessID id)
Set parent process ID.
virtual void execute(Process *previous)=0
Allow the Process to run on the CPU.
Result wakeup()
Prevent process from sleeping.
Result raiseEvent(const struct ProcessEvent *event)
Raise kernel event.
bool contains(const T &item) const
Look if an item exists on the Queue.
Size remove(T value)
Remove all items with the given value.
T & pop()
Remove item from the tail of the Queue.
virtual Size count() const
Returns the number of items in the Queue.
bool push(const T &item)
Add item to the head of the Queue.
Responsible for deciding which Process may execute on the local Core.
Result dequeue(Process *proc, bool ignoreState)
Remove a Process from the run schedule.
Process * select()
Select the next process to run.
Result enqueue(Process *proc, bool ignoreState)
Add a Process to the run schedule.
virtual void fill(T value)
Fill the Sequence with the given value.
Represents a configurable timer device.
bool isExpired(const Info &info) const
Check if a timer value is expired.
virtual Size size() const
Returns the maximum size of this Vector.
virtual int insert(const T &item)
Adds the given item to the Vector, if possible.
static Kernel * instance()
Retrieve the instance.
#define MAX_PROCS
Maximum number of processes.
#define assert(exp)
Insert program diagnostics.
#define NULL
NULL means zero.
u32 ProcessID
Process Identification Number.
unsigned int u32
Unsigned 32-bit number.
unsigned long Address
A memory address.
#define ERROR(msg)
Output an error message.
#define FATAL(msg)
Output a critical message and terminate program immediatly.
unsigned int uint
Unsigned integer number.
unsigned int Size
Any sane size indicator cannot go negative.
#define DEBUG(msg)
Output a debug message to standard output.
Represents a process which may run on the host.
Timer information structure.