summaryrefslogtreecommitdiff
path: root/Source/Kernel/TaskManager
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel/TaskManager')
-rw-r--r--Source/Kernel/TaskManager/Mutex.class.cpp26
-rw-r--r--Source/Kernel/TaskManager/Mutex.class.h16
-rw-r--r--Source/Kernel/TaskManager/Process.class.cpp11
-rw-r--r--Source/Kernel/TaskManager/Process.class.h7
-rw-r--r--Source/Kernel/TaskManager/Task.ns.cpp6
-rw-r--r--Source/Kernel/TaskManager/Task.ns.h3
6 files changed, 64 insertions, 5 deletions
diff --git a/Source/Kernel/TaskManager/Mutex.class.cpp b/Source/Kernel/TaskManager/Mutex.class.cpp
new file mode 100644
index 0000000..55226ff
--- /dev/null
+++ b/Source/Kernel/TaskManager/Mutex.class.cpp
@@ -0,0 +1,26 @@
+#include "Mutex.class.h"
+#include <TaskManager/Task.ns.h>
+
+Mutex::Mutex(bool locked) {
+ m_locked = locked;
+}
+
+bool Mutex::lock() {
+ if (m_locked) return false;
+ m_locked = true;
+ return m_locked;
+}
+
+void Mutex::waitLock() {
+ while (m_locked)
+ Task::currentThread->sleep(10); //Wait 10ms
+ m_locked = true;
+}
+
+void Mutex::unlock() {
+ m_locked = false;
+}
+
+bool Mutex::locked() {
+ return m_locked;
+}
diff --git a/Source/Kernel/TaskManager/Mutex.class.h b/Source/Kernel/TaskManager/Mutex.class.h
new file mode 100644
index 0000000..298ed9c
--- /dev/null
+++ b/Source/Kernel/TaskManager/Mutex.class.h
@@ -0,0 +1,16 @@
+#ifndef DEF_MUTEX_CLASS_H
+#define DEF_MUTEX_CLASS_H
+
+class Mutex {
+ private:
+ bool m_locked;
+
+ public:
+ Mutex(bool locked = false);
+ bool lock(); //Locks the mutex if it is not locked. Returns true if mutex could be locked, false if already locked
+ void waitLock(); //Locks the mutex, waiting for it to be unlocked before if necessary
+ void unlock();
+ bool locked();
+};
+
+#endif
diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp
index 5330719..3363ab0 100644
--- a/Source/Kernel/TaskManager/Process.class.cpp
+++ b/Source/Kernel/TaskManager/Process.class.cpp
@@ -5,7 +5,7 @@
Process::Process() { //Private constructor, does nothing
}
-Process* Process::createKernel(String cmdline) {
+Process* Process::createKernel(String cmdline, VirtualTerminal *vt) {
Process* p = new Process();
p->m_pid = 0;
p->m_cmdline = cmdline;
@@ -35,6 +35,7 @@ Process::Process(String cmdline, u32int uid) {
m_state = P_RUNNING;
m_pagedir = new PageDirectory(kernelPageDirectory);
m_uid = uid;
+ m_vt = Task::currentProcess->getVirtualTerminal();
m_stacksstart = 0xC0000000;
}
@@ -83,3 +84,11 @@ void Process::threadFinishes(Thread* thread, u32int retval) {
PageDirectory* Process::getPagedir() {
return m_pagedir;
}
+
+VirtualTerminal* Process::getVirtualTerminal() {
+ return m_vt;
+}
+
+void Process::setVirtualTerminal(VirtualTerminal* vt) {
+ m_vt = vt;
+}
diff --git a/Source/Kernel/TaskManager/Process.class.h b/Source/Kernel/TaskManager/Process.class.h
index 4ee7fcf..3b05f80 100644
--- a/Source/Kernel/TaskManager/Process.class.h
+++ b/Source/Kernel/TaskManager/Process.class.h
@@ -4,6 +4,7 @@
#include <Library/String.class.h>
#include <Library/Vector.class.h>
#include <MemoryManager/PageDirectory.class.h>
+#include <VTManager/VirtualTerminal.class.h>
#define P_ZOMBIE 0
#define P_RUNNING 1
@@ -30,11 +31,12 @@ class Process {
PageDirectory* m_pagedir;
u32int m_uid; //User ID
u32int m_stacksstart;
+ VirtualTerminal *m_vt;
Vector<Thread*> m_threads;
public:
- static Process* createKernel(String cmdline); //Also creates a Thread for what's curently happening
+ static Process* createKernel(String cmdline, VirtualTerminal *vt); //Also creates a Thread for what's curently happening
Process(String cmdline, u32int uid);
~Process();
@@ -45,6 +47,9 @@ class Process {
PageDirectory* getPagedir();
+ VirtualTerminal* getVirtualTerminal();
+ void setVirtualTerminal(VirtualTerminal* vt);
+
};
#endif
diff --git a/Source/Kernel/TaskManager/Task.ns.cpp b/Source/Kernel/TaskManager/Task.ns.cpp
index a95fd86..89e1b09 100644
--- a/Source/Kernel/TaskManager/Task.ns.cpp
+++ b/Source/Kernel/TaskManager/Task.ns.cpp
@@ -17,13 +17,15 @@ u32int currentThreadId = 0;
u32int nextpid = 1;
-void initialize(String cmdline) {
+void initialize(String cmdline, VirtualTerminal *vt) {
+ asm volatile ("cli");
threads.clear();
processes.clear();
- currentProcess = Process::createKernel(cmdline);
+ currentProcess = Process::createKernel(cmdline, vt);
idleThread = new Thread(idle_task, true);
currentThread = threads[0];
currentThreadId = 0;
+ asm volatile ("sti");
}
Thread* nextThread() {
diff --git a/Source/Kernel/TaskManager/Task.ns.h b/Source/Kernel/TaskManager/Task.ns.h
index cc658f0..db7933c 100644
--- a/Source/Kernel/TaskManager/Task.ns.h
+++ b/Source/Kernel/TaskManager/Task.ns.h
@@ -2,12 +2,13 @@
#define DEF_TASK_NS_H
#include <TaskManager/Thread.class.h>
+#include <VTManager/VirtualTerminal.class.h>
namespace Task {
extern Thread* currentThread;
extern Process* currentProcess;
- void initialize(String cmdline); //cmdline should be the bootloader kernel command line, if anybody needs it
+ void initialize(String cmdline, VirtualTerminal *vt); //cmdline should be the bootloader kernel command line, if anybody needs it
void doSwitch();
void triggerSwitch();
u32int nextPid();