Files
mango/include/kernel/wait.h
Max Wash 7c630ece54 sched: add wait begin/end functions that don't change thread state
these functions can be used when waiting on multiple queues at once, to prevent
the thread state from being changed unexpectedly while initialising a set of wait items.
2026-03-14 22:20:10 +00:00

46 lines
1.6 KiB
C

#ifndef KERNEL_WAIT_H_
#define KERNEL_WAIT_H_
#include <kernel/locks.h>
#include <kernel/queue.h>
#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); \
})
struct wait_item {
struct thread *w_thread;
struct queue_entry w_entry;
};
struct waitqueue {
struct queue wq_waiters;
spin_lock_t wq_lock;
};
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 thread_wait_begin_nosleep(
struct wait_item *waiter,
struct waitqueue *q);
extern void thread_wait_end_nosleep(
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);
#endif