| 1 | #pragma once |
| 2 | #include <sync/spinlock.h> |
| 3 | #include <thread/queue.h> |
| 4 | |
| 5 | #define CONDVAR_INIT_IRQ_DISABLE true |
| 6 | #define CONDVAR_INIT_NORMAL false |
| 7 | |
| 8 | typedef void (*condvar_callback)(void *); |
| 9 | typedef void (*thread_action_callback)(struct thread *woke); |
| 10 | |
| 11 | struct condvar { |
| 12 | struct thread_queue waiters; |
| 13 | bool irq_disable; |
| 14 | }; |
| 15 | |
| 16 | /* wait object */ |
| 17 | struct condvar_with_cb { |
| 18 | struct condvar *cv; |
| 19 | condvar_callback cb; |
| 20 | void *cb_arg; |
| 21 | size_t cookie; |
| 22 | }; |
| 23 | |
| 24 | enum wake_reason condvar_wait(struct condvar *cv, struct spinlock *lock, |
| 25 | enum irql irql, enum irql *out); |
| 26 | |
| 27 | void condvar_init(struct condvar *cv, bool irq_disable); |
| 28 | struct thread *condvar_signal(struct condvar *cv); |
| 29 | struct thread *condvar_signal_callback(struct condvar *cv, |
| 30 | thread_action_callback cb); |
| 31 | |
| 32 | void condvar_broadcast_callback(struct condvar *cv, thread_action_callback cb); |
| 33 | |
| 34 | void condvar_broadcast(struct condvar *cv); |
| 35 | |
| 36 | enum wake_reason condvar_wait_timeout(struct condvar *cv, struct spinlock *lock, |
| 37 | time_t timeout_ms, enum irql irql, |
| 38 | enum irql *out); |
| 39 | |