Kernel: Thread is no longer RefCounted
This makes developement with Scheduler much easier against compiler optimizations. I could now remove the pragma GCC optimize stuff.
This commit is contained in:
@@ -44,7 +44,7 @@ namespace Kernel
|
||||
BAN::String working_directory() const;
|
||||
BAN::ErrorOr<void> set_working_directory(BAN::StringView);
|
||||
|
||||
static BAN::RefPtr<Process> current() { return Thread::current()->process(); }
|
||||
static BAN::RefPtr<Process> current() { return Thread::current().process(); }
|
||||
|
||||
private:
|
||||
Process(pid_t pid) : m_pid(pid) {}
|
||||
@@ -70,7 +70,7 @@ namespace Kernel
|
||||
|
||||
const pid_t m_pid = 0;
|
||||
BAN::String m_working_directory;
|
||||
BAN::Vector<BAN::RefPtr<Thread>> m_threads;
|
||||
BAN::Vector<Thread*> m_threads;
|
||||
|
||||
friend class BAN::RefPtr<Process>;
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Kernel
|
||||
void start();
|
||||
void reschedule();
|
||||
|
||||
BAN::ErrorOr<void> add_thread(BAN::RefPtr<Thread>);
|
||||
BAN::ErrorOr<void> add_thread(Thread*);
|
||||
|
||||
void set_current_thread_sleeping(uint64_t);
|
||||
[[noreturn]] void set_current_thread_done();
|
||||
@@ -25,7 +25,7 @@ namespace Kernel
|
||||
void block_current_thread(Semaphore*);
|
||||
void unblock_threads(Semaphore*);
|
||||
|
||||
BAN::RefPtr<Thread> current_thread();
|
||||
Thread& current_thread();
|
||||
|
||||
private:
|
||||
Scheduler() = default;
|
||||
@@ -39,27 +39,27 @@ namespace Kernel
|
||||
private:
|
||||
struct ActiveThread
|
||||
{
|
||||
ActiveThread(const BAN::RefPtr<Thread>& thread) : thread(thread) {}
|
||||
BAN::RefPtr<Thread> thread;
|
||||
uint64_t padding = 0;
|
||||
ActiveThread(Thread* thread) : thread(thread) {}
|
||||
Thread* thread;
|
||||
uint64_t padding;
|
||||
};
|
||||
|
||||
struct SleepingThread
|
||||
{
|
||||
SleepingThread(const BAN::RefPtr<Thread>& thread, uint64_t wake_time) : thread(thread), wake_time(wake_time) {}
|
||||
BAN::RefPtr<Thread> thread;
|
||||
SleepingThread(Thread* thread, uint64_t wake_time) : thread(thread), wake_time(wake_time) {}
|
||||
Thread* thread;
|
||||
uint64_t wake_time;
|
||||
};
|
||||
|
||||
struct BlockingThread
|
||||
{
|
||||
BlockingThread(const BAN::RefPtr<Thread>& thread, Semaphore* semaphore) : thread(thread), semaphore(semaphore) {}
|
||||
BAN::RefPtr<Thread> thread;
|
||||
BlockingThread(Thread* thread, Semaphore* semaphore) : thread(thread), semaphore(semaphore) {}
|
||||
Thread* thread;
|
||||
Semaphore* semaphore;
|
||||
uint8_t padding[sizeof(uint64_t) - sizeof(Semaphore*)];
|
||||
};
|
||||
|
||||
BAN::RefPtr<Thread> m_idle_thread;
|
||||
Thread* m_idle_thread { nullptr };
|
||||
BAN::LinkedList<ActiveThread> m_active_threads;
|
||||
BAN::LinkedList<SleepingThread> m_sleeping_threads;
|
||||
BAN::LinkedList<BlockingThread> m_blocking_threads;
|
||||
|
||||
@@ -10,13 +10,16 @@ namespace Kernel
|
||||
|
||||
class Process;
|
||||
|
||||
class Thread : public BAN::RefCounted<Thread>
|
||||
class Thread
|
||||
{
|
||||
BAN_NON_COPYABLE(Thread);
|
||||
BAN_NON_MOVABLE(Thread);
|
||||
|
||||
public:
|
||||
using entry_t = void(*)(void*);
|
||||
|
||||
public:
|
||||
static BAN::ErrorOr<BAN::RefPtr<Thread>> create(entry_t, void* = nullptr, BAN::RefPtr<Process> = nullptr);
|
||||
static BAN::ErrorOr<Thread*> create(entry_t, void* = nullptr, BAN::RefPtr<Process> = nullptr);
|
||||
~Thread();
|
||||
|
||||
pid_t tid() const { return m_tid; }
|
||||
@@ -29,7 +32,7 @@ namespace Kernel
|
||||
void set_started() { m_started = true; }
|
||||
bool started() const { return m_started; }
|
||||
|
||||
static BAN::RefPtr<Thread> current() ;
|
||||
static Thread& current() ;
|
||||
BAN::RefPtr<Process> process();
|
||||
|
||||
private:
|
||||
@@ -45,8 +48,6 @@ namespace Kernel
|
||||
const pid_t m_tid = 0;
|
||||
bool m_started = false;
|
||||
BAN::RefPtr<Process> m_process;
|
||||
|
||||
friend class BAN::RefPtr<Thread>;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user