From 244df8bd2c52db9d9c9b59b917206dafcd275ebe Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 11 Oct 2009 17:28:45 +0200 Subject: Added a single linked list simple class (SimpleList) --- Source/Kernel/Library/SimpleList.class.h | 54 ++++++++++++++++++++++++++++++ Source/Kernel/Melon.ke | Bin 165535 -> 166272 bytes Source/Kernel/Shell/KernelShell.class.cpp | 2 +- Source/Kernel/TaskManager/Task.ns.cpp | 23 ++++++------- 4 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 Source/Kernel/Library/SimpleList.class.h diff --git a/Source/Kernel/Library/SimpleList.class.h b/Source/Kernel/Library/SimpleList.class.h new file mode 100644 index 0000000..c0ea111 --- /dev/null +++ b/Source/Kernel/Library/SimpleList.class.h @@ -0,0 +1,54 @@ +#ifndef DEF_SIMPLELIST_CLASS_H +#define DEF_SIMPLELIST_CLASS_H + +/* This class implements a singly linked list. It is also used to represent one of its elements. */ + +template +class SimpleList { + protected: + T m_value; + SimpleList* m_next; + + public: + SimpleList(const T& value, SimpleList* next = 0) : m_value(value), m_next(next) {} + ~SimpleList() { + if (m_next != 0) + delete m_next; + } + + T& v() { return m_value; } + T& operator* () { return m_value; } + + SimpleList* cons(const T& value) { + return new SimpleList(value, this); + } + + SimpleList* next() { + return m_next; + } + + SimpleList* delThis() { + SimpleList* ret = m_next; + Mem::kfree(this); + return ret; + } + + void delNext() { + if (m_next == 0) return; + SimpleList* temp = m_next; + m_next = m_next->m_next; + Mem::kfree(temp); + } + + bool isEnd() { + return m_next == 0; + } + + u32int size() { + if (m_next == 0) + return 0; + return m_next->size() + 1; + } +}; + +#endif diff --git a/Source/Kernel/Melon.ke b/Source/Kernel/Melon.ke index 8a8a0e8..d9ddeff 100755 Binary files a/Source/Kernel/Melon.ke and b/Source/Kernel/Melon.ke differ diff --git a/Source/Kernel/Shell/KernelShell.class.cpp b/Source/Kernel/Shell/KernelShell.class.cpp index d05487f..3d76ee0 100644 --- a/Source/Kernel/Shell/KernelShell.class.cpp +++ b/Source/Kernel/Shell/KernelShell.class.cpp @@ -2,6 +2,7 @@ #include #include #include +#include u32int KernelShell::m_instances = 0; @@ -30,7 +31,6 @@ KernelShell::~KernelShell() { } u32int KernelShell::run() { - struct { const char* name; void (KernelShell::*cmd)(Vector&); diff --git a/Source/Kernel/TaskManager/Task.ns.cpp b/Source/Kernel/TaskManager/Task.ns.cpp index a32c8c0..30610d1 100644 --- a/Source/Kernel/TaskManager/Task.ns.cpp +++ b/Source/Kernel/TaskManager/Task.ns.cpp @@ -1,5 +1,6 @@ #include "Task.ns.h" #include +#include //From Task.wtf.asm extern "C" u32int read_eip(); @@ -13,8 +14,9 @@ Vector threads; struct finished_thread_t { //Forms a linked list Thread* thread; u32int errcode; - finished_thread_t *next; -} *firstFinishedThread = 0; +}; + +SimpleList *firstFinishedThread = 0; Thread* currentThread = NULL; Process* currentProcess = NULL; @@ -38,11 +40,9 @@ Thread* nextThread() { //Clean up finished threads while (firstFinishedThread != 0) { DEBUG_HEX((u32int)firstFinishedThread); - if (firstFinishedThread->thread == currentThread) break; - firstFinishedThread->thread->finish(firstFinishedThread->errcode); - finished_thread_t* t = firstFinishedThread; - firstFinishedThread = t->next; - delete t; + if (firstFinishedThread->v().thread == currentThread) break; + firstFinishedThread->v().thread->finish(firstFinishedThread->v().errcode); + firstFinishedThread = firstFinishedThread->delThis(); } for (u32int i = 0; i < threads.size(); i++) { if (threads[i] == currentThread) { @@ -56,7 +56,7 @@ Thread* nextThread() { nid++; if (nid >= threads.size()) nid = 0; if (threads[nid]->runnable() and threads[nid] != idleThread) { - if (firstFinishedThread != 0 and firstFinishedThread->thread == threads[nid]) return idleThread; + if (firstFinishedThread != 0 and firstFinishedThread->v().thread == threads[nid]) return idleThread; currentThreadId = nid; return threads[nid]; } @@ -128,11 +128,8 @@ Process* getKernelProcess() { } void currentThreadExits(u32int errcode) { - finished_thread_t *t = new finished_thread_t; - t->thread = currentThread; - t->errcode = errcode; - t->next = firstFinishedThread; - firstFinishedThread = t; + finished_thread_t tmp = {currentThread, errcode}; + firstFinishedThread = firstFinishedThread->cons(tmp); } void registerThread(Thread* t) { -- cgit v1.2.3