1 /*
2  * Copyright (C) 2004, 2007  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 2000, 2001  Internet Software Consortium.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15  * PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /* $Id: condition.h,v 1.6 2007/06/19 23:47:18 tbox Exp $ */
19 
20 /*
21  * This provides a limited subset of the isc_condition_t
22  * functionality for use by single-threaded programs that
23  * need to block waiting for events.   Only a single
24  * call to isc_condition_wait() may be blocked at any given
25  * time, and the _waituntil and _broadcast functions are not
26  * supported.  This is intended primarily for use by the omapi
27  * library, and may go away once omapi goes away.  Use for
28  * other purposes is strongly discouraged.
29  */
30 
31 #ifndef ISC_CONDITION_H
32 #define ISC_CONDITION_H 1
33 
34 #include <isc/mutex.h>
35 
36 typedef int isc_condition_t;
37 
38 isc_result_t isc__nothread_wait_hack(isc_condition_t *cp, isc_mutex_t *mp);
39 isc_result_t isc__nothread_signal_hack(isc_condition_t *cp);
40 
41 #define isc_condition_init(cp) \
42 	(*(cp) = 0, ISC_R_SUCCESS)
43 
44 #define isc_condition_wait(cp, mp) \
45 	isc__nothread_wait_hack(cp, mp)
46 
47 #define isc_condition_waituntil(cp, mp, tp) \
48 	((void)(cp), (void)(mp), (void)(tp), ISC_R_NOTIMPLEMENTED)
49 
50 #define isc_condition_signal(cp) \
51 	isc__nothread_signal_hack(cp)
52 
53 #define isc_condition_broadcast(cp) \
54 	((void)(cp), ISC_R_NOTIMPLEMENTED)
55 
56 #define isc_condition_destroy(cp) \
57 	(*(cp) == 0 ? (*(cp) = -1, ISC_R_SUCCESS) : ISC_R_UNEXPECTED)
58 
59 #endif /* ISC_CONDITION_H */
60