2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
8 * This file is part of the SPL, Solaris Porting Layer.
10 * The SPL is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
15 * The SPL is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * You should have received a copy of the GNU General Public License along
21 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
24 #ifndef _SPL_CONDVAR_H
25 #define _SPL_CONDVAR_H
27 #include <linux/module.h>
29 #include <sys/mutex.h>
30 #include <sys/callo.h>
35 * cv_timedwait() is similar to cv_wait() except that it additionally expects
36 * a timeout value specified in ticks. When woken by cv_signal() or
37 * cv_broadcast() it returns 1, otherwise when the timeout is reached -1 is
40 * cv_timedwait_sig() behaves the same as cv_timedwait() but blocks
41 * interruptibly and can be woken by a signal (EINTR, ERESTART). When
42 * this occurs 0 is returned.
44 * cv_timedwait_io() and cv_timedwait_sig_io() are variants of cv_timedwait()
45 * and cv_timedwait_sig() which should be used when waiting for outstanding
46 * IO to complete. They are responsible for updating the iowait accounting
47 * when this is supported by the platform.
49 * cv_timedwait_hires() and cv_timedwait_sig_hires() are high resolution
50 * versions of cv_timedwait() and cv_timedwait_sig(). They expect the timeout
51 * to be specified as a hrtime_t allowing for timeouts of less than a tick.
53 * N.B. The return values differ slightly from the illumos implementation
54 * which returns the time remaining, instead of 1, when woken. They both
55 * return -1 on timeout. Consumers which need to know the time remaining
56 * are responsible for tracking it themselves.
61 * The kcondvar_t struct is protected by mutex taken externally before
62 * calling any of the wait/signal funs, and passed into the wait funs.
64 #define CV_MAGIC 0x346545f4
65 #define CV_DESTROY 0x346545f5
69 wait_queue_head_t cv_event
;
70 wait_queue_head_t cv_destroy
;
76 typedef enum { CV_DEFAULT
= 0, CV_DRIVER
} kcv_type_t
;
78 extern void __cv_init(kcondvar_t
*, char *, kcv_type_t
, void *);
79 extern void __cv_destroy(kcondvar_t
*);
80 extern void __cv_wait(kcondvar_t
*, kmutex_t
*);
81 extern void __cv_wait_io(kcondvar_t
*, kmutex_t
*);
82 extern void __cv_wait_idle(kcondvar_t
*, kmutex_t
*);
83 extern int __cv_wait_io_sig(kcondvar_t
*, kmutex_t
*);
84 extern int __cv_wait_sig(kcondvar_t
*, kmutex_t
*);
85 extern int __cv_timedwait(kcondvar_t
*, kmutex_t
*, clock_t);
86 extern int __cv_timedwait_io(kcondvar_t
*, kmutex_t
*, clock_t);
87 extern int __cv_timedwait_sig(kcondvar_t
*, kmutex_t
*, clock_t);
88 extern int __cv_timedwait_idle(kcondvar_t
*, kmutex_t
*, clock_t);
89 extern int cv_timedwait_hires(kcondvar_t
*, kmutex_t
*, hrtime_t
,
90 hrtime_t res
, int flag
);
91 extern int cv_timedwait_sig_hires(kcondvar_t
*, kmutex_t
*, hrtime_t
,
92 hrtime_t res
, int flag
);
93 extern int cv_timedwait_idle_hires(kcondvar_t
*, kmutex_t
*, hrtime_t
,
94 hrtime_t res
, int flag
);
95 extern void __cv_signal(kcondvar_t
*);
96 extern void __cv_broadcast(kcondvar_t
*c
);
98 #define cv_init(cvp, name, type, arg) __cv_init(cvp, name, type, arg)
99 #define cv_destroy(cvp) __cv_destroy(cvp)
100 #define cv_wait(cvp, mp) __cv_wait(cvp, mp)
101 #define cv_wait_io(cvp, mp) __cv_wait_io(cvp, mp)
102 #define cv_wait_idle(cvp, mp) __cv_wait_idle(cvp, mp)
103 #define cv_wait_io_sig(cvp, mp) __cv_wait_io_sig(cvp, mp)
104 #define cv_wait_sig(cvp, mp) __cv_wait_sig(cvp, mp)
105 #define cv_signal(cvp) __cv_signal(cvp)
106 #define cv_broadcast(cvp) __cv_broadcast(cvp)
109 * NB: There is no way to reliably distinguish between having been signalled
110 * and having timed out on Linux. If the client code needs to reliably
111 * distinguish between the two it should use the hires variant.
113 #define cv_timedwait(cvp, mp, t) __cv_timedwait(cvp, mp, t)
114 #define cv_timedwait_io(cvp, mp, t) __cv_timedwait_io(cvp, mp, t)
115 #define cv_timedwait_sig(cvp, mp, t) __cv_timedwait_sig(cvp, mp, t)
116 #define cv_timedwait_idle(cvp, mp, t) __cv_timedwait_idle(cvp, mp, t)
119 #endif /* _SPL_CONDVAR_H */