Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / isc / pthreads / condition.c
blobe840a30bf0d1e4966de420ca72dea76378594316
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1998-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.
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.
18 /* $Id: condition.c,v 1.30.2.2 2004/03/09 06:12:06 marka Exp $ */
20 #include <config.h>
22 #include <errno.h>
24 #include <isc/condition.h>
25 #include <isc/msgs.h>
26 #include <isc/strerror.h>
27 #include <isc/string.h>
28 #include <isc/time.h>
29 #include <isc/util.h>
31 isc_result_t
32 isc_condition_waituntil(isc_condition_t *c, isc_mutex_t *m, isc_time_t *t) {
33 int presult;
34 isc_result_t result;
35 struct timespec ts;
36 char strbuf[ISC_STRERRORSIZE];
38 REQUIRE(c != NULL && m != NULL && t != NULL);
41 * POSIX defines a timespec's tv_sec as time_t.
43 result = isc_time_secondsastimet(t, &ts.tv_sec);
44 if (result != ISC_R_SUCCESS)
45 return (result);
48 * POSIX defines a timespec's tv_nsec as long. isc_time_nanoseconds
49 * ensures its return value is < 1 billion, which will fit in a long.
51 ts.tv_nsec = (long)isc_time_nanoseconds(t);
53 do {
54 #if ISC_MUTEX_PROFILE
55 presult = pthread_cond_timedwait(c, &m->mutex, &ts);
56 #else
57 presult = pthread_cond_timedwait(c, m, &ts);
58 #endif
59 if (presult == 0)
60 return (ISC_R_SUCCESS);
61 if (presult == ETIMEDOUT)
62 return (ISC_R_TIMEDOUT);
63 } while (presult == EINTR);
65 isc__strerror(presult, strbuf, sizeof(strbuf));
66 UNEXPECTED_ERROR(__FILE__, __LINE__,
67 "pthread_cond_timedwait() %s %s",
68 isc_msgcat_get(isc_msgcat, ISC_MSGSET_GENERAL,
69 ISC_MSG_RETURNED, "returned"),
70 strbuf);
71 return (ISC_R_UNEXPECTED);