]> git.proxmox.com Git - mirror_spl-debian.git/blob - include/sys/condvar.h
Add cv_wait_interruptible() function.
[mirror_spl-debian.git] / include / sys / condvar.h
1 /*
2 * This file is part of the SPL: Solaris Porting Layer.
3 *
4 * Copyright (c) 2008 Lawrence Livermore National Security, LLC.
5 * Produced at Lawrence Livermore National Laboratory
6 * Written by:
7 * Brian Behlendorf <behlendorf1@llnl.gov>,
8 * Herb Wartens <wartens2@llnl.gov>,
9 * Jim Garlick <garlick@llnl.gov>
10 * UCRL-CODE-235197
11 *
12 * This is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 */
26
27 #ifndef _SPL_CONDVAR_H
28 #define _SPL_CONDVAR_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include <linux/module.h>
35 #include <linux/wait.h>
36 #include <sys/kmem.h>
37 #include <sys/mutex.h>
38
39 /* The kcondvar_t struct is protected by mutex taken externally before
40 * calling any of the wait/signal funs, and passed into the wait funs.
41 */
42 #define CV_MAGIC 0x346545f4
43 #define CV_POISON 0x95
44
45 typedef struct {
46 int cv_magic;
47 char *cv_name;
48 int cv_name_size;
49 wait_queue_head_t cv_event;
50 atomic_t cv_waiters;
51 kmutex_t *cv_mutex;
52 spinlock_t cv_lock;
53 } kcondvar_t;
54
55 typedef enum { CV_DEFAULT=0, CV_DRIVER } kcv_type_t;
56
57 extern void __cv_init(kcondvar_t *cvp, char *name, kcv_type_t type, void *arg);
58 extern void __cv_destroy(kcondvar_t *cvp);
59 extern void __cv_wait(kcondvar_t *cvp, kmutex_t *mp);
60 extern void __cv_wait_interruptible(kcondvar_t *cvp, kmutex_t *mp);
61 extern clock_t __cv_timedwait(kcondvar_t *cvp, kmutex_t *mp, clock_t exp_time);
62 extern void __cv_signal(kcondvar_t *cvp);
63 extern void __cv_broadcast(kcondvar_t *cvp);
64
65 #define cv_init(cvp, name, type, arg) \
66 ({ \
67 if ((name) == NULL) \
68 __cv_init(cvp, #cvp, type, arg); \
69 else \
70 __cv_init(cvp, name, type, arg); \
71 })
72 #define cv_destroy(cvp) __cv_destroy(cvp)
73 #define cv_wait(cvp, mp) __cv_wait(cvp, mp)
74 #define cv_wait_interruptible(cvp, mp) __cv_wait_interruptible(cvp, mp)
75 #define cv_timedwait(cvp, mp, t) __cv_timedwait(cvp, mp, t)
76 #define cv_signal(cvp) __cv_signal(cvp)
77 #define cv_broadcast(cvp) __cv_broadcast(cvp)
78
79 #endif /* _SPL_CONDVAR_H */