40 lines
1.4 KiB
C
40 lines
1.4 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 wait_on_queue(struct waitqueue *q);
|
|
extern void wakeup_queue(struct waitqueue *q);
|
|
extern void wakeup_one(struct waitqueue *q);
|
|
|
|
#endif
|