Kernel: Implement somewhat functioning multithread support
This still uses only a single cpu, but we can now have 'parallelization' This seems to work fine in qemu and bochs, but my own computer did not like this when I last tried. I have absolutely no idea how multithreading should actually be implmemented and I just thought and implemented the most simple one I could think of. This might not be in any way correct :D
This commit is contained in:
34
kernel/include/kernel/Scheduler.h
Normal file
34
kernel/include/kernel/Scheduler.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/LinkedList.h>
|
||||
#include <kernel/Thread.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
class Scheduler
|
||||
{
|
||||
BAN_NON_COPYABLE(Scheduler);
|
||||
BAN_NON_MOVABLE(Scheduler);
|
||||
|
||||
public:
|
||||
static void Initialize();
|
||||
static Scheduler& Get();
|
||||
|
||||
const Thread& CurrentThread() const;
|
||||
|
||||
void AddThread(void(*)());
|
||||
void Switch();
|
||||
void Start();
|
||||
|
||||
static constexpr size_t ms_between_switch = 4;
|
||||
|
||||
private:
|
||||
Scheduler() {}
|
||||
|
||||
private:
|
||||
BAN::LinkedList<Thread> m_threads;
|
||||
BAN::LinkedList<Thread>::iterator m_current_iterator;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user