sched: implement waitqueues

This commit is contained in:
2023-05-10 20:29:57 +01:00
parent b3957b311a
commit 63f27adb1b
3 changed files with 100 additions and 0 deletions

View File

@@ -12,10 +12,27 @@
#define PRIO_MAX 32
#define THREAD_KSTACK_ORDER VM_PAGE_4K
#define wait_event(wq, cond) \
({ \
struct thread *self = current_thread(); \
struct wait_item waiter; \
wait_item_init(&waiter, self); \
for (;;) { \
thread_wait_begin(&waiter, wq); \
if (cond) { \
break; \
} \
schedule(SCHED_NORMAL); \
} \
thread_wait_end(&waiter, wq); \
})
#ifdef __cplusplus
extern "C" {
#endif
struct runqueue;
enum task_state {
TASK_RUNNING,
TASK_STOPPED,
@@ -83,6 +100,8 @@ struct thread {
uintptr_t tr_sp, tr_bp;
struct runqueue *tr_rq;
struct queue_entry tr_threads;
struct queue_entry tr_rqentry;
@@ -174,6 +193,13 @@ extern void remove_timer(struct timer *timer);
extern unsigned long schedule_timeout(unsigned long clock_ticks);
extern unsigned long milli_sleep(unsigned long ms);
extern void wait_item_init(struct wait_item *item, struct thread *thr);
extern void thread_wait_begin(struct wait_item *waiter, struct waitqueue *q);
extern void thread_wait_end(struct wait_item *waiter, struct waitqueue *q);
extern void wait_on_queue(struct waitqueue *q);
extern void wakeup_queue(struct waitqueue *q);
extern void wakeup_one(struct waitqueue *q);
#ifdef __cplusplus
}
#endif