FreeNOS
Public Types | Public Member Functions | Private Member Functions | Private Attributes
ProcessManager Class Reference

Represents a process which may run on the host. More...

#include <ProcessManager.h>

Public Types

enum  Result {
  Success, InvalidArgument, IOError, WakeupPending,
  AlreadyExists
}
 Result code. More...
 

Public Member Functions

 ProcessManager ()
 Constructor function. More...
 
virtual ~ProcessManager ()
 Destructor function. More...
 
Processcreate (const Address entry, const MemoryMap &map, const bool readyToRun=false, const bool privileged=false)
 Create a new Process. More...
 
Processget (const ProcessID id)
 Retrieve a Process by it's ID. More...
 
void remove (Process *proc, const uint exitStatus=0)
 Remove a Process. More...
 
Result schedule ()
 Schedule next process to run. More...
 
Result wait (Process *proc)
 Let current Process wait for another Process to terminate. More...
 
Result stop (Process *proc)
 Remove given Process from the Scheduler. More...
 
Result resume (Process *proc)
 Resume scheduling of the given Process. More...
 
Result reset (Process *proc, const Address entry)
 Restart execution of a Process at the given entry point. More...
 
Result sleep (const Timer::Info *timer=0, const bool ignoreWakeups=false)
 Let current Process sleep until a timer expires or wakeup occurs. More...
 
Result wakeup (Process *proc)
 Take Process out of Sleep state and mark ready for execution. More...
 
Result raiseEvent (Process *proc, const struct ProcessEvent *event)
 Raise kernel event for a Process. More...
 
Result registerInterruptNotify (Process *proc, const u32 vector)
 Register an interrupt notification for a Process. More...
 
Result unregisterInterruptNotify (Process *proc)
 Remove all interrupt notifications for a Process. More...
 
Result interruptNotify (const u32 vector)
 Raise interrupt notifications for a interrupt vector. More...
 
void setIdle (Process *proc)
 Set the idle process. More...
 
Processcurrent ()
 Current process running. More...
 

Private Member Functions

Result enqueueProcess (Process *proc, const bool ignoreState=false)
 Place the given process on the Schedule queue. More...
 
Result dequeueProcess (Process *proc, const bool ignoreState=false) const
 Remove the given process on the Schedule queue. More...
 

Private Attributes

Index< Process, MAX_PROCSm_procs
 All known Processes. More...
 
Schedulerm_scheduler
 Object which selects processes to run. More...
 
Processm_current
 Currently executing process. More...
 
Processm_idle
 Idle process. More...
 
Queue< Process *, MAX_PROCSm_sleepTimerQueue
 Queue with sleeping processes waiting for a Timer to expire. More...
 
Vector< List< Process * > * > m_interruptNotifyList
 Interrupt notification list. More...
 

Detailed Description

Represents a process which may run on the host.

Definition at line 44 of file ProcessManager.h.

Member Enumeration Documentation

◆ Result

Result code.

Enumerator
Success 
InvalidArgument 
IOError 
WakeupPending 
AlreadyExists 

Definition at line 51 of file ProcessManager.h.

Constructor & Destructor Documentation

◆ ProcessManager()

ProcessManager::ProcessManager ( )

Constructor function.

Definition at line 25 of file ProcessManager.cpp.

References DEBUG, Sequence< T >::fill(), m_current, m_idle, m_interruptNotifyList, m_scheduler, MAX_PROCS, and ZERO.

◆ ~ProcessManager()

ProcessManager::~ProcessManager ( )
virtual

Destructor function.

Definition at line 37 of file ProcessManager.cpp.

References m_scheduler, and NULL.

Member Function Documentation

◆ create()

Process * ProcessManager::create ( const Address  entry,
const MemoryMap map,
const bool  readyToRun = false,
const bool  privileged = false 
)

Create a new Process.

Parameters
entryProcess executable entry point
mapMemory mapping
readyToRunTrue to immediately run the Process or false to sleep.
privilegedTrue to create a privileged Process
Returns
Process pointer on success or ZERO on failure

Definition at line 45 of file ProcessManager.cpp.

References entry, ERROR, Process::getID(), Process::initialize(), Index< T, N >::insert(), Index< T, N >::insertAt(), m_current, m_procs, Index< T, N >::remove(), resume(), Process::setParent(), Process::Success, and ZERO.

Referenced by Kernel::loadBootProgram(), and ProcessCtlHandler().

◆ current()

Process * ProcessManager::current ( )

◆ dequeueProcess()

ProcessManager::Result ProcessManager::dequeueProcess ( Process proc,
const bool  ignoreState = false 
) const
private

Remove the given process on the Schedule queue.

Parameters
procProcess pointer
ignoreStateTrue to not check for the Process state prior to dequeue.
Returns
Result code

Definition at line 414 of file ProcessManager.cpp.

References Scheduler::dequeue(), ERROR, Process::getID(), IOError, m_scheduler, Scheduler::Success, and Success.

Referenced by remove(), setIdle(), sleep(), stop(), and wait().

◆ enqueueProcess()

ProcessManager::Result ProcessManager::enqueueProcess ( Process proc,
const bool  ignoreState = false 
)
private

Place the given process on the Schedule queue.

Parameters
procProcess pointer
ignoreStateTrue to not check for the Process state prior to dequeue.
Returns
Result code

Definition at line 399 of file ProcessManager.cpp.

References assert, Scheduler::enqueue(), ERROR, Process::getID(), IOError, m_scheduler, m_sleepTimerQueue, Queue< T, N >::remove(), Scheduler::Success, and Success.

Referenced by raiseEvent(), remove(), resume(), and wakeup().

◆ get()

Process * ProcessManager::get ( const ProcessID  id)

Retrieve a Process by it's ID.

Parameters
idProcessID number.
Returns
Pointer to the appropriate process or ZERO if not found.

Definition at line 95 of file ProcessManager.cpp.

References Index< T, N >::get(), and m_procs.

Referenced by ProcessShares::createShare(), ProcessCtlHandler(), ProcessShares::releaseShare(), ARMKernel::trap(), VMCopyHandler(), VMCtlHandler(), VMShareHandler(), and ProcessShares::~ProcessShares().

◆ interruptNotify()

ProcessManager::Result ProcessManager::interruptNotify ( const u32  vector)

Raise interrupt notifications for a interrupt vector.

Parameters
vectorInterrupt vector
Returns
Result code

Definition at line 376 of file ProcessManager.cpp.

References ERROR, ListIterator< T >::hasCurrent(), InterruptEvent, IOError, m_interruptNotifyList, raiseEvent(), Success, and ProcessEvent::type.

Referenced by Kernel::executeIntVector().

◆ raiseEvent()

ProcessManager::Result ProcessManager::raiseEvent ( Process proc,
const struct ProcessEvent event 
)

Raise kernel event for a Process.

Parameters
procProcess pointer
eventEvent to raise
Returns
Result code

Definition at line 325 of file ProcessManager.cpp.

References enqueueProcess(), ERROR, Process::getID(), IOError, Process::raiseEvent(), Success, Process::Success, and Process::WakeupPending.

Referenced by ProcessShares::createShare(), interruptNotify(), and ProcessShares::~ProcessShares().

◆ registerInterruptNotify()

ProcessManager::Result ProcessManager::registerInterruptNotify ( Process proc,
const u32  vector 
)

Register an interrupt notification for a Process.

Parameters
procProcess pointer
vectorInterrupt vector number
Returns
Result code

Definition at line 344 of file ProcessManager.cpp.

References AlreadyExists, Vector< T >::insert(), m_interruptNotifyList, and Success.

Referenced by ProcessCtlHandler().

◆ remove()

void ProcessManager::remove ( Process proc,
const uint  exitStatus = 0 
)

◆ reset()

ProcessManager::Result ProcessManager::reset ( Process proc,
const Address  entry 
)

Restart execution of a Process at the given entry point.

Parameters
procProcess pointer
entryAddress to begin execution.

Definition at line 262 of file ProcessManager.cpp.

References entry, ERROR, IOError, m_current, Process::reset(), and Success.

Referenced by ProcessCtlHandler().

◆ resume()

ProcessManager::Result ProcessManager::resume ( Process proc)

Resume scheduling of the given Process.

Parameters
procProcess pointer
Returns
Result code

Definition at line 250 of file ProcessManager.cpp.

References enqueueProcess(), ERROR, Process::getID(), IOError, Process::resume(), and Process::Success.

Referenced by create(), and ProcessCtlHandler().

◆ schedule()

ProcessManager::Result ProcessManager::schedule ( )

◆ setIdle()

void ProcessManager::setIdle ( Process proc)

Set the idle process.

Definition at line 208 of file ProcessManager.cpp.

References dequeueProcess(), FATAL, Process::getID(), m_idle, and Success.

Referenced by PrivExecHandler().

◆ sleep()

ProcessManager::Result ProcessManager::sleep ( const Timer::Info timer = 0,
const bool  ignoreWakeups = false 
)

Let current Process sleep until a timer expires or wakeup occurs.

Parameters
timerTimer on which the process must be woken up (if expired), or ZERO for no limit
ignoreWakeupsTrue to enter Sleep state regardless of pending wakeups
Returns
Result code

Definition at line 274 of file ProcessManager.cpp.

References assert, Queue< T, N >::contains(), dequeueProcess(), ERROR, FATAL, Process::getID(), IOError, m_current, m_sleepTimerQueue, Queue< T, N >::push(), Process::sleep(), Success, Process::Success, WakeupPending, and Process::WakeupPending.

Referenced by ProcessCtlHandler().

◆ stop()

ProcessManager::Result ProcessManager::stop ( Process proc)

Remove given Process from the Scheduler.

Parameters
procProcess pointer
Returns
Result code

Definition at line 230 of file ProcessManager.cpp.

References dequeueProcess(), ERROR, Process::getID(), Process::getState(), IOError, Process::Ready, Process::stop(), Success, and Process::Success.

Referenced by ProcessCtlHandler().

◆ unregisterInterruptNotify()

ProcessManager::Result ProcessManager::unregisterInterruptNotify ( Process proc)

Remove all interrupt notifications for a Process.

Parameters
procProcess pointer
Returns
Result code

Definition at line 361 of file ProcessManager.cpp.

References m_interruptNotifyList, List< T >::remove(), Vector< T >::size(), and Success.

Referenced by remove().

◆ wait()

ProcessManager::Result ProcessManager::wait ( Process proc)

Let current Process wait for another Process to terminate.

Parameters
procProcess pointer
Returns
Result code

Definition at line 219 of file ProcessManager.cpp.

References dequeueProcess(), ERROR, Process::getID(), IOError, m_current, Process::Success, and Process::wait().

Referenced by ProcessCtlHandler().

◆ wakeup()

ProcessManager::Result ProcessManager::wakeup ( Process proc)

Take Process out of Sleep state and mark ready for execution.

Parameters
procProcess pointer
Returns
Result code

Definition at line 306 of file ProcessManager.cpp.

References enqueueProcess(), ERROR, Process::getID(), IOError, Success, Process::Success, Process::wakeup(), and Process::WakeupPending.

Referenced by ProcessCtlHandler(), and schedule().

Field Documentation

◆ m_current

Process* ProcessManager::m_current
private

Currently executing process.

Definition at line 243 of file ProcessManager.h.

Referenced by create(), current(), ProcessManager(), remove(), reset(), schedule(), sleep(), and wait().

◆ m_idle

Process* ProcessManager::m_idle
private

Idle process.

Definition at line 246 of file ProcessManager.h.

Referenced by ProcessManager(), remove(), schedule(), and setIdle().

◆ m_interruptNotifyList

Vector<List<Process *> *> ProcessManager::m_interruptNotifyList
private

Interrupt notification list.

Definition at line 252 of file ProcessManager.h.

Referenced by interruptNotify(), ProcessManager(), registerInterruptNotify(), and unregisterInterruptNotify().

◆ m_procs

Index<Process, MAX_PROCS> ProcessManager::m_procs
private

All known Processes.

Definition at line 237 of file ProcessManager.h.

Referenced by create(), get(), and remove().

◆ m_scheduler

Scheduler* ProcessManager::m_scheduler
private

Object which selects processes to run.

Definition at line 240 of file ProcessManager.h.

Referenced by dequeueProcess(), enqueueProcess(), ProcessManager(), schedule(), and ~ProcessManager().

◆ m_sleepTimerQueue

Queue<Process *, MAX_PROCS> ProcessManager::m_sleepTimerQueue
private

Queue with sleeping processes waiting for a Timer to expire.

Definition at line 249 of file ProcessManager.h.

Referenced by enqueueProcess(), remove(), schedule(), and sleep().


The documentation for this class was generated from the following files: