]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/sys/condvar.h
Rework condition variable implementation to be consistent with
[mirror_spl-debian.git] / include / sys / condvar.h
1 #ifndef _SPL_CONDVAR_H
2 #define _SPL_CONDVAR_H
3
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 #include <linux/module.h>
9 #include <linux/wait.h>
10 #include <sys/mutex.h>
11
12 /* The kcondvar_t struct is protected by mutex taken externally before
13 * calling any of the wait/signal funs, and passed into the wait funs.
14 */
15 #define CV_MAGIC 0x346545f4
16 #define CV_POISON 0x95
17
18 typedef struct {
19 int cv_magic;
20 char *cv_name;
21 int cv_name_size;
22 wait_queue_head_t cv_event;
23 atomic_t cv_waiters;
24 kmutex_t *cv_mutex;
25 spinlock_t cv_lock;
26 } kcondvar_t;
27
28 typedef enum { CV_DEFAULT=0, CV_DRIVER } kcv_type_t;
29
30 extern void __cv_init(kcondvar_t *cvp, char *name, kcv_type_t type, void *arg);
31 extern void __cv_destroy(kcondvar_t *cvp);
32 extern void __cv_wait(kcondvar_t *cvp, kmutex_t *mp);
33 extern clock_t __cv_timedwait(kcondvar_t *cvp, kmutex_t *mp,
34 clock_t expire_time);
35 extern void __cv_signal(kcondvar_t *cvp);
36 extern void __cv_broadcast(kcondvar_t *cvp);
37
38 #define cv_init(cvp, name, type, arg) \
39 ({ \
40 if ((name) == NULL) \
41 __cv_init(cvp, #cvp, type, arg); \
42 else \
43 __cv_init(cvp, name, type, arg); \
44 })
45 #define cv_destroy(cvp) __cv_destroy(cvp)
46 #define cv_wait(cvp, mp) __cv_wait(cvp, mp)
47 #define cv_timedwait(cvp, mp, t) __cv_timedwait(cvp, mp, t)
48 #define cv_signal(cvp) __cv_signal(cvp)
49 #define cv_broadcast(cvp) __cv_broadcast(cvp)
50
51 #endif /* _SPL_CONDVAR_H */