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