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