summaryrefslogtreecommitdiff
path: root/Source/Kernel/TaskManager
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-09-18 14:26:29 +0200
committerAlexis211 <alexis211@gmail.com>2009-09-18 14:26:29 +0200
commitf593816bc9c32a8570cf65697183f314348e8e87 (patch)
treeae4cb3fbc64834818a6aabe04cfdd429e9da70b5 /Source/Kernel/TaskManager
parent8862994499de563b763607fff3f39a8a28c553b3 (diff)
downloadMelon-f593816bc9c32a8570cf65697183f314348e8e87.tar.gz
Melon-f593816bc9c32a8570cf65697183f314348e8e87.zip
Changes in mutexes, vectors and VTs :
mutexes now use the atomic_exchang defined in Task.wtf.asm some vector methods are now declared const VTs now can display (decimal) 64bit integers
Diffstat (limited to 'Source/Kernel/TaskManager')
-rw-r--r--Source/Kernel/TaskManager/Mutex.class.cpp14
-rw-r--r--Source/Kernel/TaskManager/Mutex.class.h9
-rw-r--r--Source/Kernel/TaskManager/Task.wtf.asm7
3 files changed, 21 insertions, 9 deletions
diff --git a/Source/Kernel/TaskManager/Mutex.class.cpp b/Source/Kernel/TaskManager/Mutex.class.cpp
index 55226ff..67234d8 100644
--- a/Source/Kernel/TaskManager/Mutex.class.cpp
+++ b/Source/Kernel/TaskManager/Mutex.class.cpp
@@ -1,24 +1,24 @@
#include "Mutex.class.h"
#include <TaskManager/Task.ns.h>
-Mutex::Mutex(bool locked) {
+extern "C" u32int atomic_exchange(u32int* ptr, u32int newval);
+
+Mutex::Mutex(u32int locked) {
m_locked = locked;
}
bool Mutex::lock() {
- if (m_locked) return false;
- m_locked = true;
- return m_locked;
+ if (atomic_exchange(&m_locked, MUTEX_TRUE) == MUTEX_TRUE) return false; //The lock was already locked
+ return true;
}
void Mutex::waitLock() {
- while (m_locked)
+ while (atomic_exchange(&m_locked, MUTEX_TRUE) == MUTEX_TRUE)
Task::currentThread->sleep(10); //Wait 10ms
- m_locked = true;
}
void Mutex::unlock() {
- m_locked = false;
+ m_locked = MUTEX_FALSE;
}
bool Mutex::locked() {
diff --git a/Source/Kernel/TaskManager/Mutex.class.h b/Source/Kernel/TaskManager/Mutex.class.h
index 298ed9c..5545559 100644
--- a/Source/Kernel/TaskManager/Mutex.class.h
+++ b/Source/Kernel/TaskManager/Mutex.class.h
@@ -1,12 +1,17 @@
#ifndef DEF_MUTEX_CLASS_H
#define DEF_MUTEX_CLASS_H
+#include <Core/common.wtf.h>
+
+#define MUTEX_FALSE 0
+#define MUTEX_TRUE 1
+
class Mutex {
private:
- bool m_locked;
+ u32int m_locked;
public:
- Mutex(bool locked = false);
+ Mutex(u32int locked = MUTEX_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();
diff --git a/Source/Kernel/TaskManager/Task.wtf.asm b/Source/Kernel/TaskManager/Task.wtf.asm
index 2c14f28..77db18e 100644
--- a/Source/Kernel/TaskManager/Task.wtf.asm
+++ b/Source/Kernel/TaskManager/Task.wtf.asm
@@ -9,6 +9,13 @@ idle_task:
hlt
jmp idle_task
+[GLOBAL atomic_exchange]
+atomic_exchange:
+ mov ecx, [esp+4] ; Get lock address
+ mov eax, [esp+8] ; Get new value
+ xchg eax, [ecx] ; Old value goes in eax
+ ret
+
[GLOBAL copy_page_physical]
copy_page_physical:
push ebx ; According to __cdecl, we must preserve the contents of EBX.