2022-12-07 15:03:34 +01:00
|
|
|
#pragma once
|
2023-03-11 10:34:08 +01:00
|
|
|
#include "fs/VFS.h"
|
2022-12-07 15:03:34 +01:00
|
|
|
#include "thread/Thread.h"
|
|
|
|
|
|
|
|
namespace Scheduler
|
|
|
|
{
|
|
|
|
void init();
|
|
|
|
|
|
|
|
Thread* current();
|
2022-12-07 15:55:58 +01:00
|
|
|
Thread* idle();
|
2022-12-07 15:03:34 +01:00
|
|
|
|
2023-03-24 21:05:38 +01:00
|
|
|
Result<void> new_kernel_thread(u64 address, const char* name);
|
|
|
|
Result<void> new_kernel_thread(void (*func)(void), const char* name);
|
|
|
|
Result<void> new_kernel_thread(void (*func)(void*), void* arg, const char* name);
|
2022-12-07 15:03:34 +01:00
|
|
|
|
2023-04-28 13:23:07 +02:00
|
|
|
Result<Thread*> new_userspace_thread(SharedPtr<VFS::Inode> inode, const char* name);
|
2023-01-05 21:52:26 +01:00
|
|
|
|
2023-03-18 23:45:48 +01:00
|
|
|
void add_thread(Thread* thread);
|
|
|
|
|
2022-12-07 15:03:34 +01:00
|
|
|
Thread* pick_task();
|
|
|
|
|
2022-12-19 12:24:15 +01:00
|
|
|
void reap_thread(Thread* thread);
|
|
|
|
|
2022-12-07 15:03:34 +01:00
|
|
|
void switch_task(Registers* regs);
|
|
|
|
|
|
|
|
void invoke(Registers* regs);
|
2022-12-18 18:43:34 +01:00
|
|
|
|
2022-12-19 12:43:23 +01:00
|
|
|
LinkedList<Thread> check_for_dying_threads();
|
2023-03-23 22:42:24 +01:00
|
|
|
|
|
|
|
Option<Thread*> find_by_pid(pid_t pid);
|
2023-03-24 17:37:04 +01:00
|
|
|
|
2023-04-28 15:19:01 +02:00
|
|
|
template <typename Callback> void for_each_child(Thread* thread, Callback callback)
|
2023-03-24 17:37:04 +01:00
|
|
|
{
|
2023-04-28 15:19:01 +02:00
|
|
|
for (Thread* current = thread; current; current = g_threads.next(current).value_or(nullptr))
|
2023-04-28 15:13:53 +02:00
|
|
|
{
|
2023-04-28 15:22:16 +02:00
|
|
|
if (current->parent_id == thread->id)
|
2023-04-28 15:13:53 +02:00
|
|
|
{
|
2023-04-28 15:19:01 +02:00
|
|
|
bool should_continue = callback(current);
|
2023-04-28 15:13:53 +02:00
|
|
|
if (!should_continue) return;
|
|
|
|
}
|
|
|
|
}
|
2023-03-24 17:37:04 +01:00
|
|
|
}
|
|
|
|
|
2023-04-28 15:19:01 +02:00
|
|
|
bool has_children(Thread* thread);
|
2023-03-24 17:37:04 +01:00
|
|
|
|
2023-04-28 15:19:01 +02:00
|
|
|
Option<Thread*> find_exited_child(Thread* thread);
|
2022-12-07 15:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void kernel_yield();
|
2022-12-18 18:43:34 +01:00
|
|
|
void kernel_sleep(u64 ms);
|
2023-01-02 13:07:29 +01:00
|
|
|
[[noreturn]] void kernel_exit();
|