mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-05 17:15:31 +00:00
In a number of situations in pthreads-related code, a common sequence of steps is taken: if the value returned by a library function is not 0, pass errno to strerror_r(), log the string returned by the latter, and immediately abort execution. Add an ERRNO_CHECK() preprocessor macro which takes those exact steps and use it wherever (conveniently) possible. Notes: 1. The "log the return value of strerror_r() and abort" pattern is used in a number of other places that this commit does not touch; only "!= 0" checks followed by isc_error_fatal() calls with non-customized error messages are replaced here. 2. This change temporarily breaks file name & line number reporting for isc__mutex_init() errors, to prevent breaking the build. This issue will be rectified in a subsequent change.
-
55 lines
1.5 KiB
C
55 lines
1.5 KiB
C
/*
|
|
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
|
*
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*
|
|
* See the COPYRIGHT file distributed with this work for additional
|
|
* information regarding copyright ownership.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
/*! \file */
|
|
|
|
#include <errno.h>
|
|
|
|
#include <isc/error.h>
|
|
#include <isc/lang.h>
|
|
#include <isc/mutex.h>
|
|
#include <isc/result.h>
|
|
#include <isc/string.h>
|
|
#include <isc/types.h>
|
|
#include <isc/util.h>
|
|
|
|
typedef pthread_cond_t isc_condition_t;
|
|
|
|
#define isc_condition_init(cond) \
|
|
{ \
|
|
int _ret = pthread_cond_init(cond, NULL); \
|
|
ERRNO_CHECK(pthread_cond_init, _ret); \
|
|
}
|
|
|
|
#define isc_condition_wait(cp, mp) \
|
|
((pthread_cond_wait((cp), (mp)) == 0) ? ISC_R_SUCCESS \
|
|
: ISC_R_UNEXPECTED)
|
|
|
|
#define isc_condition_signal(cp) \
|
|
((pthread_cond_signal((cp)) == 0) ? ISC_R_SUCCESS : ISC_R_UNEXPECTED)
|
|
|
|
#define isc_condition_broadcast(cp) \
|
|
((pthread_cond_broadcast((cp)) == 0) ? ISC_R_SUCCESS : ISC_R_UNEXPECTED)
|
|
|
|
#define isc_condition_destroy(cp) \
|
|
((pthread_cond_destroy((cp)) == 0) ? ISC_R_SUCCESS : ISC_R_UNEXPECTED)
|
|
|
|
ISC_LANG_BEGINDECLS
|
|
|
|
isc_result_t
|
|
isc_condition_waituntil(isc_condition_t *, isc_mutex_t *, isc_time_t *);
|
|
|
|
ISC_LANG_ENDDECLS
|