mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-03 08:05:21 +00:00
Remove atomics emulated by a mutex-locked variable
Mutex atomics were intended to be used as a debugging tool only and it has already served its purpose and it's not needed anymore.
This commit is contained in:
@@ -968,30 +968,6 @@ unit:clang:tsan:
|
||||
- job: clang:tsan
|
||||
artifacts: true
|
||||
|
||||
# Jobs for builds with mutex-based atomics on Debian 10 "buster" (amd64)
|
||||
|
||||
gcc:mutexatomics:
|
||||
variables:
|
||||
CC: gcc
|
||||
CFLAGS: "${CFLAGS_COMMON}"
|
||||
EXTRA_CONFIGURE: "--with-libidn2 --enable-mutex-atomics"
|
||||
<<: *base_image
|
||||
<<: *build_job
|
||||
|
||||
system:gcc:mutexatomics:
|
||||
<<: *base_image
|
||||
<<: *system_test_job
|
||||
needs:
|
||||
- job: gcc:mutexatomics
|
||||
artifacts: true
|
||||
|
||||
unit:gcc:mutexatomics:
|
||||
<<: *base_image
|
||||
<<: *unit_test_job
|
||||
needs:
|
||||
- job: gcc:mutexatomics
|
||||
artifacts: true
|
||||
|
||||
# Jobs for Clang builds on Debian 10 "buster" (amd64)
|
||||
|
||||
clang:buster:amd64:
|
||||
|
22
configure.ac
22
configure.ac
@@ -248,28 +248,6 @@ AS_IF([test "$enable_fuzzing" = "afl"],
|
||||
[AC_MSG_ERROR([set CC=afl-<gcc|clang> when --enable-fuzzing=afl is used])])
|
||||
])
|
||||
|
||||
# [pairwise: --enable-mutex-atomics, --disable-mutex-atomics]
|
||||
AC_ARG_ENABLE(mutex_atomics,
|
||||
AS_HELP_STRING([--enable-mutex-atomics],
|
||||
[emulate atomics by mutex-locked variables, useful for debugging
|
||||
[default=no]]),
|
||||
[],
|
||||
[enable_mutex_atomics=no])
|
||||
|
||||
AC_MSG_CHECKING([whether to emulate atomics with mutexes])
|
||||
case "$enable_mutex_atomics" in
|
||||
yes)
|
||||
AC_MSG_RESULT(yes)
|
||||
AC_DEFINE(ISC_MUTEX_ATOMICS, 1, [Define to emulate atomic variables with mutexes.])
|
||||
;;
|
||||
no)
|
||||
AC_MSG_RESULT(no)
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR("--enable-mutex-atomics requires yes or no")
|
||||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# Perl is optional; it is used only by some of the system test scripts.
|
||||
#
|
||||
|
@@ -1450,11 +1450,9 @@ init_rdataset(dns_rbtdb_t *rbtdb, rdatasetheader_t *h) {
|
||||
atomic_init(&h->attributes, 0);
|
||||
atomic_init(&h->last_refresh_fail_ts, 0);
|
||||
|
||||
#ifndef ISC_MUTEX_ATOMICS
|
||||
STATIC_ASSERT((sizeof(h->attributes) == 2),
|
||||
"The .attributes field of rdatasetheader_t needs to be "
|
||||
"16-bit int type exactly.");
|
||||
#endif /* !ISC_MUTEX_ATOMICS */
|
||||
|
||||
#if TRACE_HEADER
|
||||
if (IS_CACHE(rbtdb) && rbtdb->common.rdclass == dns_rdataclass_in) {
|
||||
@@ -7520,9 +7518,6 @@ rbt_datafixer(dns_rbtnode_t *rbtnode, void *base, size_t filesize, void *arg,
|
||||
header->is_mmapped = 1;
|
||||
header->node = rbtnode;
|
||||
header->node_is_relative = 0;
|
||||
#ifdef ISC_MUTEX_ATOMICS
|
||||
atomic_init(&header->attributes, header->attributes.v);
|
||||
#endif
|
||||
|
||||
if (RESIGN(header) &&
|
||||
(header->resign != 0 || header->resign_lsb != 0)) {
|
||||
|
@@ -55,7 +55,6 @@ libisc_la_HEADERS = \
|
||||
include/isc/mem.h \
|
||||
include/isc/meminfo.h \
|
||||
include/isc/mutex.h \
|
||||
include/isc/mutexatomic.h \
|
||||
include/isc/mutexblock.h \
|
||||
include/isc/net.h \
|
||||
include/isc/netaddr.h \
|
||||
|
@@ -11,15 +11,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef ISC_MUTEX_ATOMICS
|
||||
#include <isc/mutexatomic.h>
|
||||
#else /* ifdef ISC_MUTEX_ATOMICS */
|
||||
#if HAVE_STDATOMIC_H
|
||||
#include <stdatomic.h>
|
||||
#else /* if HAVE_STDATOMIC_H */
|
||||
#include <isc/stdatomic.h>
|
||||
#endif /* if HAVE_STDATOMIC_H */
|
||||
#endif /* ifdef ISC_MUTEX_ATOMICS */
|
||||
|
||||
/*
|
||||
* We define a few additional macros to make things easier
|
||||
|
@@ -1,252 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* 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
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#if HAVE_UCHAR_H
|
||||
#include <uchar.h>
|
||||
#endif /* HAVE_UCHAR_H */
|
||||
|
||||
#include <isc/mutex.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#if !defined(__has_feature)
|
||||
#define __has_feature(x) 0
|
||||
#endif /* if !defined(__has_feature) */
|
||||
|
||||
#if !defined(__has_extension)
|
||||
#define __has_extension(x) __has_feature(x)
|
||||
#endif /* if !defined(__has_extension) */
|
||||
|
||||
#if !defined(__GNUC_PREREQ__)
|
||||
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
|
||||
#define __GNUC_PREREQ__(maj, min) \
|
||||
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
|
||||
#else /* if defined(__GNUC__) && defined(__GNUC_MINOR__) */
|
||||
#define __GNUC_PREREQ__(maj, min) 0
|
||||
#endif /* if defined(__GNUC__) && defined(__GNUC_MINOR__) */
|
||||
#endif /* if !defined(__GNUC_PREREQ__) */
|
||||
|
||||
#if !defined(__CLANG_ATOMICS) && !defined(__GNUC_ATOMICS)
|
||||
#if __has_extension(c_atomic) || __has_extension(cxx_atomic)
|
||||
#define __CLANG_ATOMICS
|
||||
#elif __GNUC_PREREQ__(4, 7)
|
||||
#define __GNUC_ATOMICS
|
||||
#elif !defined(__GNUC__)
|
||||
#error "isc/stdatomic.h does not support your compiler"
|
||||
#endif /* if __has_extension(c_atomic) || __has_extension(cxx_atomic) */
|
||||
#endif /* if !defined(__CLANG_ATOMICS) && !defined(__GNUC_ATOMICS) */
|
||||
|
||||
#ifndef __ATOMIC_RELAXED
|
||||
#define __ATOMIC_RELAXED 0
|
||||
#endif /* ifndef __ATOMIC_RELAXED */
|
||||
#ifndef __ATOMIC_CONSUME
|
||||
#define __ATOMIC_CONSUME 1
|
||||
#endif /* ifndef __ATOMIC_CONSUME */
|
||||
#ifndef __ATOMIC_ACQUIRE
|
||||
#define __ATOMIC_ACQUIRE 2
|
||||
#endif /* ifndef __ATOMIC_ACQUIRE */
|
||||
#ifndef __ATOMIC_RELEASE
|
||||
#define __ATOMIC_RELEASE 3
|
||||
#endif /* ifndef __ATOMIC_RELEASE */
|
||||
#ifndef __ATOMIC_ACQ_REL
|
||||
#define __ATOMIC_ACQ_REL 4
|
||||
#endif /* ifndef __ATOMIC_ACQ_REL */
|
||||
#ifndef __ATOMIC_SEQ_CST
|
||||
#define __ATOMIC_SEQ_CST 5
|
||||
#endif /* ifndef __ATOMIC_SEQ_CST */
|
||||
|
||||
enum memory_order {
|
||||
memory_order_relaxed = __ATOMIC_RELAXED,
|
||||
memory_order_consume = __ATOMIC_CONSUME,
|
||||
memory_order_acquire = __ATOMIC_ACQUIRE,
|
||||
memory_order_release = __ATOMIC_RELEASE,
|
||||
memory_order_acq_rel = __ATOMIC_ACQ_REL,
|
||||
memory_order_seq_cst = __ATOMIC_SEQ_CST
|
||||
};
|
||||
|
||||
typedef enum memory_order memory_order;
|
||||
|
||||
#define ___TYPEDEF(type, name, orig) \
|
||||
typedef struct name { \
|
||||
isc_mutex_t m; \
|
||||
orig v; \
|
||||
} type;
|
||||
|
||||
#define _TYPEDEF_S(type) ___TYPEDEF(atomic_##type, atomic_##type##_s, type)
|
||||
#define _TYPEDEF_O(type, orig) \
|
||||
___TYPEDEF(atomic_##type, atomic_##type##_s, orig)
|
||||
#define _TYPEDEF_T(type) \
|
||||
___TYPEDEF(atomic_##type##_t, atomic_##type##_s, type##_t)
|
||||
|
||||
#ifndef HAVE_UCHAR_H
|
||||
typedef uint_least16_t char16_t;
|
||||
typedef uint_least32_t char32_t;
|
||||
#endif /* HAVE_UCHAR_H */
|
||||
|
||||
_TYPEDEF_S(bool);
|
||||
_TYPEDEF_S(char);
|
||||
_TYPEDEF_O(schar, signed char);
|
||||
_TYPEDEF_O(uchar, unsigned char);
|
||||
_TYPEDEF_S(short);
|
||||
_TYPEDEF_O(ushort, unsigned short);
|
||||
_TYPEDEF_S(int);
|
||||
_TYPEDEF_O(uint, unsigned int);
|
||||
_TYPEDEF_S(long);
|
||||
_TYPEDEF_O(ulong, unsigned long);
|
||||
_TYPEDEF_O(llong, long long);
|
||||
_TYPEDEF_O(ullong, unsigned long long);
|
||||
_TYPEDEF_T(char16);
|
||||
_TYPEDEF_T(char32);
|
||||
_TYPEDEF_T(wchar);
|
||||
_TYPEDEF_T(int_least8);
|
||||
_TYPEDEF_T(uint_least8);
|
||||
_TYPEDEF_T(int_least16);
|
||||
_TYPEDEF_T(uint_least16);
|
||||
_TYPEDEF_T(int_least32);
|
||||
_TYPEDEF_T(uint_least32);
|
||||
_TYPEDEF_T(int_least64);
|
||||
_TYPEDEF_T(uint_least64);
|
||||
_TYPEDEF_T(int_fast8);
|
||||
_TYPEDEF_T(uint_fast8);
|
||||
_TYPEDEF_T(int_fast16);
|
||||
_TYPEDEF_T(uint_fast16);
|
||||
_TYPEDEF_T(int_fast32);
|
||||
_TYPEDEF_T(uint_fast32);
|
||||
_TYPEDEF_T(int_fast64);
|
||||
_TYPEDEF_T(uint_fast64);
|
||||
_TYPEDEF_T(intptr);
|
||||
_TYPEDEF_T(uintptr);
|
||||
_TYPEDEF_T(size);
|
||||
_TYPEDEF_T(ptrdiff);
|
||||
_TYPEDEF_T(intmax);
|
||||
_TYPEDEF_T(uintmax);
|
||||
|
||||
#undef ___TYPEDEF
|
||||
#undef _TYPEDEF_S
|
||||
#undef _TYPEDEF_T
|
||||
#undef _TYPEDEF_O
|
||||
|
||||
#define ATOMIC_VAR_INIT(arg) \
|
||||
{ \
|
||||
.m = PTHREAD_MUTEX_INITIALIZER, .v = arg \
|
||||
}
|
||||
|
||||
#define atomic_init(obj, desired) \
|
||||
{ \
|
||||
isc_mutex_init(&(obj)->m); \
|
||||
(obj)->v = desired; \
|
||||
}
|
||||
#define atomic_load_explicit(obj, order) \
|
||||
({ \
|
||||
typeof((obj)->v) ___v; \
|
||||
REQUIRE(isc_mutex_lock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v = (obj)->v; \
|
||||
REQUIRE(isc_mutex_unlock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v; \
|
||||
})
|
||||
#define atomic_store_explicit(obj, desired, order) \
|
||||
{ \
|
||||
REQUIRE(isc_mutex_lock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
(obj)->v = desired; \
|
||||
REQUIRE(isc_mutex_unlock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
}
|
||||
#define atomic_fetch_add_explicit(obj, arg, order) \
|
||||
({ \
|
||||
typeof((obj)->v) ___v; \
|
||||
REQUIRE(isc_mutex_lock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v = (obj)->v; \
|
||||
(obj)->v += arg; \
|
||||
REQUIRE(isc_mutex_unlock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v; \
|
||||
})
|
||||
#define atomic_fetch_sub_explicit(obj, arg, order) \
|
||||
({ \
|
||||
typeof((obj)->v) ___v; \
|
||||
REQUIRE(isc_mutex_lock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v = (obj)->v; \
|
||||
(obj)->v -= arg; \
|
||||
REQUIRE(isc_mutex_unlock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v; \
|
||||
})
|
||||
#define atomic_fetch_and_explicit(obj, arg, order) \
|
||||
({ \
|
||||
typeof((obj)->v) ___v; \
|
||||
REQUIRE(isc_mutex_lock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v = (obj)->v; \
|
||||
(obj)->v &= arg; \
|
||||
REQUIRE(isc_mutex_unlock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v; \
|
||||
})
|
||||
#define atomic_fetch_or_explicit(obj, arg, order) \
|
||||
({ \
|
||||
typeof((obj)->v) ___v; \
|
||||
REQUIRE(isc_mutex_lock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v = (obj)->v; \
|
||||
(obj)->v |= arg; \
|
||||
REQUIRE(isc_mutex_unlock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v; \
|
||||
})
|
||||
#define atomic_compare_exchange_strong_explicit(obj, expected, desired, succ, \
|
||||
fail) \
|
||||
({ \
|
||||
bool ___v; \
|
||||
REQUIRE(isc_mutex_lock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v = ((obj)->v == *expected); \
|
||||
*expected = (obj)->v; \
|
||||
(obj)->v = ___v ? desired : (obj)->v; \
|
||||
REQUIRE(isc_mutex_unlock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v; \
|
||||
})
|
||||
#define atomic_compare_exchange_weak_explicit(obj, expected, desired, succ, \
|
||||
fail) \
|
||||
({ \
|
||||
bool ___v; \
|
||||
REQUIRE(isc_mutex_lock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v = ((obj)->v == *expected); \
|
||||
*expected = (obj)->v; \
|
||||
(obj)->v = ___v ? desired : (obj)->v; \
|
||||
REQUIRE(isc_mutex_unlock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v; \
|
||||
})
|
||||
|
||||
#define atomic_load(obj) atomic_load_explicit(obj, memory_order_seq_cst)
|
||||
#define atomic_store(obj, arg) \
|
||||
atomic_store_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_fetch_add(obj, arg) \
|
||||
atomic_fetch_add_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_fetch_sub(obj, arg) \
|
||||
atomic_fetch_sub_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_fetch_and(obj, arg) \
|
||||
atomic_fetch_and_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_fetch_or(obj, arg) \
|
||||
atomic_fetch_or_explicit(obj, arg, memory_order_seq_cst)
|
||||
#define atomic_compare_exchange_strong(obj, expected, desired) \
|
||||
atomic_compare_exchange_strong_explicit(obj, expected, desired, \
|
||||
memory_order_seq_cst, \
|
||||
memory_order_seq_cst)
|
||||
#define atomic_compare_exchange_weak(obj, expected, desired) \
|
||||
atomic_compare_exchange_weak_explicit(obj, expected, desired, \
|
||||
memory_order_seq_cst, \
|
||||
memory_order_seq_cst)
|
||||
#define atomic_exchange_explicit(obj, desired, order) \
|
||||
({ \
|
||||
typeof((obj)->v) ___v; \
|
||||
REQUIRE(isc_mutex_lock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v = (obj)->v; \
|
||||
(obj)->v = desired; \
|
||||
REQUIRE(isc_mutex_unlock(&(obj)->m) == ISC_R_SUCCESS); \
|
||||
___v; \
|
||||
})
|
||||
#define atomic_exchange(obj, desired) \
|
||||
atomic_exchange_explicit(obj, desired, memory_order_seq_cst)
|
@@ -6288,14 +6288,6 @@ recparam_update(ns_query_recparam_t *param, dns_rdatatype_t qtype,
|
||||
}
|
||||
}
|
||||
static atomic_uint_fast32_t last_soft, last_hard;
|
||||
#ifdef ISC_MUTEX_ATOMICS
|
||||
static isc_once_t last_once = ISC_ONCE_INIT;
|
||||
static void
|
||||
last_init(void) {
|
||||
atomic_init(&last_soft, 0);
|
||||
atomic_init(&last_hard, 0);
|
||||
}
|
||||
#endif /* ifdef ISC_MUTEX_ATOMICS */
|
||||
|
||||
/*%
|
||||
* Check recursion quota before making the current client "recursing".
|
||||
@@ -6324,9 +6316,6 @@ check_recursionquota(ns_client_t *client) {
|
||||
}
|
||||
|
||||
if (result == ISC_R_SOFTQUOTA) {
|
||||
#ifdef ISC_MUTEX_ATOMICS
|
||||
isc_once_do(&last_once, last_init);
|
||||
#endif /* ifdef ISC_MUTEX_ATOMICS */
|
||||
isc_stdtime_t now;
|
||||
isc_stdtime_get(&now);
|
||||
if (now != atomic_load_relaxed(&last_soft)) {
|
||||
@@ -6347,9 +6336,6 @@ check_recursionquota(ns_client_t *client) {
|
||||
ns_client_killoldestquery(client);
|
||||
result = ISC_R_SUCCESS;
|
||||
} else if (result == ISC_R_QUOTA) {
|
||||
#ifdef ISC_MUTEX_ATOMICS
|
||||
isc_once_do(&last_once, last_init);
|
||||
#endif /* ifdef ISC_MUTEX_ATOMICS */
|
||||
isc_stdtime_t now;
|
||||
isc_stdtime_get(&now);
|
||||
if (now != atomic_load_relaxed(&last_hard)) {
|
||||
|
@@ -1728,7 +1728,6 @@
|
||||
./lib/isc/include/isc/mem.h C 1997,1998,1999,2000,2001,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2015,2016,2017,2018,2019,2020,2021
|
||||
./lib/isc/include/isc/meminfo.h C 2015,2016,2018,2019,2020,2021
|
||||
./lib/isc/include/isc/mutex.h C 1998,1999,2000,2001,2002,2004,2005,2007,2016,2018,2019,2020,2021
|
||||
./lib/isc/include/isc/mutexatomic.h C 2019,2020,2021
|
||||
./lib/isc/include/isc/mutexblock.h C 1999,2000,2001,2004,2005,2006,2007,2016,2018,2019,2020,2021
|
||||
./lib/isc/include/isc/net.h C 1999,2000,2001,2002,2003,2004,2005,2007,2008,2012,2013,2014,2016,2017,2018,2019,2020,2021
|
||||
./lib/isc/include/isc/netaddr.h C 1998,1999,2000,2001,2002,2004,2005,2006,2007,2009,2015,2016,2017,2018,2019,2020,2021
|
||||
|
Reference in New Issue
Block a user