FreeNOS
ProcessManager.h
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 #ifndef __KERNEL_PROCESS_MANAGER_H
19 #define __KERNEL_PROCESS_MANAGER_H
20 
21 #include <Types.h>
22 #include <MemoryMap.h>
23 #include <Vector.h>
24 #include <List.h>
25 #include <Queue.h>
26 #include "Process.h"
27 
28 /* Forward declarations */
29 class Scheduler;
30 
39 #define MAX_PROCS 1024
40 
45 {
46  public:
47 
51  enum Result
52  {
58  };
59 
60  public:
61 
66 
70  virtual ~ProcessManager();
71 
82  Process * create(const Address entry,
83  const MemoryMap &map,
84  const bool readyToRun = false,
85  const bool privileged = false);
86 
94  Process * get(const ProcessID id);
95 
99  void remove(Process *proc, const uint exitStatus = 0);
100 
106  Result schedule();
107 
115  Result wait(Process *proc);
116 
124  Result stop(Process *proc);
125 
133  Result resume(Process *proc);
134 
141  Result reset(Process *proc, const Address entry);
142 
151  Result sleep(const Timer::Info *timer = 0, const bool ignoreWakeups = false);
152 
160  Result wakeup(Process *proc);
161 
170  Result raiseEvent(Process *proc, const struct ProcessEvent *event);
171 
180  Result registerInterruptNotify(Process *proc, const u32 vector);
181 
190 
198  Result interruptNotify(const u32 vector);
199 
203  void setIdle(Process *proc);
204 
210  Process * current();
211 
212  private:
213 
222  Result enqueueProcess(Process *proc, const bool ignoreState = false);
223 
232  Result dequeueProcess(Process *proc, const bool ignoreState = false) const;
233 
234  private:
235 
238 
241 
244 
247 
250 
253 };
254 
259 #endif /* __KERNEL_PROCESS_MANAGER_H */
Scheduler
Responsible for deciding which Process may execute on the local Core.
Definition: Scheduler.h:36
ProcessManager::resume
Result resume(Process *proc)
Resume scheduling of the given Process.
Definition: ProcessManager.cpp:250
ProcessManager::m_idle
Process * m_idle
Idle process.
Definition: ProcessManager.h:246
ProcessManager::raiseEvent
Result raiseEvent(Process *proc, const struct ProcessEvent *event)
Raise kernel event for a Process.
Definition: ProcessManager.cpp:325
ProcessManager::~ProcessManager
virtual ~ProcessManager()
Destructor function.
Definition: ProcessManager.cpp:37
ProcessManager
Represents a process which may run on the host.
Definition: ProcessManager.h:44
Vector.h
ProcessManager::Result
Result
Result code.
Definition: ProcessManager.h:51
Types.h
Process
Represents a process which may run on the host.
Definition: Process.h:44
ProcessManager::reset
Result reset(Process *proc, const Address entry)
Restart execution of a Process at the given entry point.
Definition: ProcessManager.cpp:262
ProcessManager::m_current
Process * m_current
Currently executing process.
Definition: ProcessManager.h:243
ProcessManager::create
Process * create(const Address entry, const MemoryMap &map, const bool readyToRun=false, const bool privileged=false)
Create a new Process.
Definition: ProcessManager.cpp:45
ProcessManager::IOError
@ IOError
Definition: ProcessManager.h:55
ProcessManager::unregisterInterruptNotify
Result unregisterInterruptNotify(Process *proc)
Remove all interrupt notifications for a Process.
Definition: ProcessManager.cpp:361
ProcessManager::dequeueProcess
Result dequeueProcess(Process *proc, const bool ignoreState=false) const
Remove the given process on the Schedule queue.
Definition: ProcessManager.cpp:414
ProcessManager::sleep
Result sleep(const Timer::Info *timer=0, const bool ignoreWakeups=false)
Let current Process sleep until a timer expires or wakeup occurs.
Definition: ProcessManager.cpp:274
Index< Process, MAX_PROCS >
ProcessID
u32 ProcessID
Process Identification Number.
Definition: Types.h:140
Address
unsigned long Address
A memory address.
Definition: Types.h:131
Process.h
ProcessManager::wakeup
Result wakeup(Process *proc)
Take Process out of Sleep state and mark ready for execution.
Definition: ProcessManager.cpp:306
ProcessManager::wait
Result wait(Process *proc)
Let current Process wait for another Process to terminate.
Definition: ProcessManager.cpp:219
Timer::Info
Timer information structure.
Definition: Timer.h:42
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
ProcessManager::WakeupPending
@ WakeupPending
Definition: ProcessManager.h:56
ProcessManager::Success
@ Success
Definition: ProcessManager.h:53
ProcessManager::stop
Result stop(Process *proc)
Remove given Process from the Scheduler.
Definition: ProcessManager.cpp:230
ProcessEvent
Represents a process which may run on the host.
Definition: ProcessEvent.h:40
Queue.h
u32
unsigned int u32
Unsigned 32-bit number.
Definition: Types.h:53
ProcessManager::ProcessManager
ProcessManager()
Constructor function.
Definition: ProcessManager.cpp:25
MemoryMap
Describes virtual memory map layout.
Definition: MemoryMap.h:38
MemoryMap.h
ProcessManager::InvalidArgument
@ InvalidArgument
Definition: ProcessManager.h:54
ProcessManager::schedule
Result schedule()
Schedule next process to run.
Definition: ProcessManager.cpp:155
ProcessManager::get
Process * get(const ProcessID id)
Retrieve a Process by it's ID.
Definition: ProcessManager.cpp:95
ProcessManager::m_procs
Index< Process, MAX_PROCS > m_procs
All known Processes.
Definition: ProcessManager.h:237
ProcessManager::interruptNotify
Result interruptNotify(const u32 vector)
Raise interrupt notifications for a interrupt vector.
Definition: ProcessManager.cpp:376
entry
u32 entry[]
Definition: IntelACPI.h:64
ProcessManager::remove
void remove(Process *proc, const uint exitStatus=0)
Remove a Process.
Definition: ProcessManager.cpp:100
Queue< Process *, MAX_PROCS >
ProcessManager::m_sleepTimerQueue
Queue< Process *, MAX_PROCS > m_sleepTimerQueue
Queue with sleeping processes waiting for a Timer to expire.
Definition: ProcessManager.h:249
ProcessManager::m_scheduler
Scheduler * m_scheduler
Object which selects processes to run.
Definition: ProcessManager.h:240
ProcessManager::current
Process * current()
Current process running.
Definition: ProcessManager.cpp:203
Vector
Vectors are dynamically resizeable Arrays.
Definition: Vector.h:41
ProcessManager::setIdle
void setIdle(Process *proc)
Set the idle process.
Definition: ProcessManager.cpp:208
ProcessManager::m_interruptNotifyList
Vector< List< Process * > * > m_interruptNotifyList
Interrupt notification list.
Definition: ProcessManager.h:252
ProcessManager::AlreadyExists
@ AlreadyExists
Definition: ProcessManager.h:57
ProcessManager::registerInterruptNotify
Result registerInterruptNotify(Process *proc, const u32 vector)
Register an interrupt notification for a Process.
Definition: ProcessManager.cpp:344
List.h
ProcessManager::enqueueProcess
Result enqueueProcess(Process *proc, const bool ignoreState=false)
Place the given process on the Schedule queue.
Definition: ProcessManager.cpp:399