1135446Strhodes/*
2193149Sdougb * Copyright (C) 2004, 2007  Internet Systems Consortium, Inc. ("ISC")
3135446Strhodes * Copyright (C) 2000, 2001  Internet Software Consortium.
4135446Strhodes *
5193149Sdougb * Permission to use, copy, modify, and/or distribute this software for any
6135446Strhodes * purpose with or without fee is hereby granted, provided that the above
7135446Strhodes * copyright notice and this permission notice appear in all copies.
8135446Strhodes *
9135446Strhodes * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10135446Strhodes * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11135446Strhodes * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12135446Strhodes * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13135446Strhodes * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14135446Strhodes * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15135446Strhodes * PERFORMANCE OF THIS SOFTWARE.
16135446Strhodes */
17135446Strhodes
18234010Sdougb/* $Id: condition.h,v 1.6 2007/06/19 23:47:18 tbox Exp $ */
19135446Strhodes
20135446Strhodes/*
21135446Strhodes * This provides a limited subset of the isc_condition_t
22135446Strhodes * functionality for use by single-threaded programs that
23135446Strhodes * need to block waiting for events.   Only a single
24135446Strhodes * call to isc_condition_wait() may be blocked at any given
25135446Strhodes * time, and the _waituntil and _broadcast functions are not
26135446Strhodes * supported.  This is intended primarily for use by the omapi
27135446Strhodes * library, and may go away once omapi goes away.  Use for
28135446Strhodes * other purposes is strongly discouraged.
29135446Strhodes */
30135446Strhodes
31135446Strhodes#ifndef ISC_CONDITION_H
32135446Strhodes#define ISC_CONDITION_H 1
33135446Strhodes
34135446Strhodes#include <isc/mutex.h>
35135446Strhodes
36135446Strhodestypedef int isc_condition_t;
37135446Strhodes
38135446Strhodesisc_result_t isc__nothread_wait_hack(isc_condition_t *cp, isc_mutex_t *mp);
39135446Strhodesisc_result_t isc__nothread_signal_hack(isc_condition_t *cp);
40135446Strhodes
41135446Strhodes#define isc_condition_init(cp) \
42135446Strhodes	(*(cp) = 0, ISC_R_SUCCESS)
43135446Strhodes
44135446Strhodes#define isc_condition_wait(cp, mp) \
45135446Strhodes	isc__nothread_wait_hack(cp, mp)
46135446Strhodes
47135446Strhodes#define isc_condition_waituntil(cp, mp, tp) \
48135446Strhodes	((void)(cp), (void)(mp), (void)(tp), ISC_R_NOTIMPLEMENTED)
49135446Strhodes
50135446Strhodes#define isc_condition_signal(cp) \
51135446Strhodes	isc__nothread_signal_hack(cp)
52135446Strhodes
53135446Strhodes#define isc_condition_broadcast(cp) \
54135446Strhodes	((void)(cp), ISC_R_NOTIMPLEMENTED)
55135446Strhodes
56135446Strhodes#define isc_condition_destroy(cp) \
57135446Strhodes	(*(cp) == 0 ? (*(cp) = -1, ISC_R_SUCCESS) : ISC_R_UNEXPECTED)
58135446Strhodes
59135446Strhodes#endif /* ISC_CONDITION_H */
60