Kernel: Semaphores and Threads can now be blocked with timeout
This commit is contained in:
@@ -19,9 +19,9 @@ namespace Kernel
|
||||
void reschedule();
|
||||
void reschedule_if_idling();
|
||||
|
||||
void set_current_thread_sleeping(uint64_t);
|
||||
void set_current_thread_sleeping(uint64_t wake_time);
|
||||
|
||||
void block_current_thread(Semaphore*);
|
||||
void block_current_thread(Semaphore*, uint64_t wake_time);
|
||||
void unblock_threads(Semaphore*);
|
||||
// Makes sleeping or blocked thread with tid active.
|
||||
void unblock_thread(pid_t tid);
|
||||
@@ -36,6 +36,8 @@ namespace Kernel
|
||||
private:
|
||||
Scheduler() = default;
|
||||
|
||||
void set_current_thread_sleeping_impl(uint64_t wake_time);
|
||||
|
||||
void wake_threads();
|
||||
[[nodiscard]] bool save_current_thread();
|
||||
void remove_and_advance_current_thread();
|
||||
@@ -50,18 +52,14 @@ namespace Kernel
|
||||
: thread(thread)
|
||||
{}
|
||||
|
||||
Thread* thread;
|
||||
union
|
||||
{
|
||||
uint64_t wake_time;
|
||||
Semaphore* semaphore;
|
||||
};
|
||||
Thread* thread;
|
||||
uint64_t wake_time;
|
||||
Semaphore* semaphore;
|
||||
};
|
||||
|
||||
Thread* m_idle_thread { nullptr };
|
||||
BAN::LinkedList<SchedulerThread> m_active_threads;
|
||||
BAN::LinkedList<SchedulerThread> m_sleeping_threads;
|
||||
BAN::LinkedList<SchedulerThread> m_blocking_threads;
|
||||
|
||||
BAN::LinkedList<SchedulerThread>::iterator m_current_thread;
|
||||
|
||||
|
||||
@@ -6,7 +6,9 @@ namespace Kernel
|
||||
class Semaphore
|
||||
{
|
||||
public:
|
||||
void block();
|
||||
void block_indefinite();
|
||||
void block_with_timeout(uint64_t timeout_ms);
|
||||
void block_with_wake_time(uint64_t wake_time_ms);
|
||||
void unblock();
|
||||
};
|
||||
|
||||
|
||||
@@ -47,8 +47,10 @@ namespace Kernel
|
||||
void handle_signal(int signal = 0);
|
||||
bool add_signal(int signal);
|
||||
|
||||
// blocks semaphore and returns either on unblock, eintr or spuriously
|
||||
BAN::ErrorOr<void> block_or_eintr(Semaphore&);
|
||||
// blocks semaphore and returns either on unblock, eintr, spuriously or after timeout
|
||||
BAN::ErrorOr<void> block_or_eintr_indefinite(Semaphore& semaphore);
|
||||
BAN::ErrorOr<void> block_or_eintr_or_timeout(Semaphore& semaphore, uint64_t timeout_ms, bool etimedout);
|
||||
BAN::ErrorOr<void> block_or_eintr_or_waketime(Semaphore& semaphore, uint64_t wake_time_ms, bool etimedout);
|
||||
|
||||
void set_return_rsp(uintptr_t& rsp) { m_return_rsp = &rsp; }
|
||||
void set_return_rip(uintptr_t& rip) { m_return_rip = &rip; }
|
||||
|
||||
Reference in New Issue
Block a user