Kernel: Improve multithreading support

We can now use arbitary BAN::function<void(...)> as the Thread.
I also implemented multithreading for i386 since it was not done
on the initial multithreading commit.
This commit is contained in:
2023-02-02 23:24:12 +02:00
parent 777ede328e
commit 5b5e620d8a
8 changed files with 158 additions and 88 deletions

View File

@@ -13,16 +13,26 @@ namespace Kernel
BAN_NON_MOVABLE(Scheduler);
public:
static void Initialize();
static Scheduler& Get();
static void initialize();
static Scheduler& get();
const Thread& CurrentThread() const;
const Thread& current_thread() const;
void AddThread(void(*)());
void Switch();
void Start();
template<typename... Args>
void add_thread(const BAN::Function<void(Args...)>& func, Args... args)
{
uintptr_t flags;
asm volatile("pushf; pop %0" : "=r"(flags));
asm volatile("cli");
MUST(m_threads.emplace_back(func, BAN::forward<Args>(args)...));
if (flags & (1 << 9))
asm volatile("sti");
}
static constexpr size_t ms_between_switch = 4;
void switch_thread();
void start();
static constexpr size_t ms_between_switch = 1;
private:
Scheduler() {}