rsyslog/m4/atomic_operations_64bit.m4
Rainer Gerhards ab11e9c0f7 runtime: modernize atomic helper usage
Why: several hot paths used legacy atomic idioms where read-only and weak state observations paid unnecessary synchronization cost or used mutex fallbacks in signal-sensitive paths.

Impact: common counters and weak flags use cheaper atomic operations on modern compilers while preserving fallback behavior for older platforms.

Before/After: before, helpers leaned on __sync fetch operations and some signal flags used mutex-backed access; after, helpers use __atomic operations with explicit relaxed/acquire/release intent and signal-safe weak flag access.

Technical Overview:

Replace legacy __sync-based helper implementations with __atomic forms.

Remove the now-unused separate load/store autoconf probe.

Add relaxed helper variants for statistics and weak object state paths.

Use PREFER_* helpers for signal-observed flags that tolerate weak fallback reads.

Keep bHadHUP set until doHUP() completes for imdiag AwaitHUPComplete.

Preserve 64-bit/time_t fallback mutexes for platforms without 64-bit atomics.

Adjust sanitizer suppressions for known helper-access false positives.

Join tcpsrv and imbeats workers before tearing down shared listener state.

Add a small mmutf8fix regression coverage improvement touched by this work.

With the help of AI-Agents: Codex
2026-07-02 12:46:12 +02:00

61 lines
1.7 KiB
Plaintext

# rsyslog
#
# atomic_operations.m4 - autoconf macro to check if compiler supports atomic
# operations
#
# rgerhards, 2008-09-18, added based on
# http://svn.apache.org/repos/asf/apr/apr/trunk/configure.in
#
#
AC_DEFUN([RS_ATOMIC_OPERATIONS_64BIT],
[AC_CACHE_CHECK([whether the compiler provides atomic builtins for 64 bit data types], [ap_cv_atomic_builtins_64],
[AC_TRY_RUN([
int main()
{
unsigned long long val = 1010, tmp, *mem = &val;
void *ptr = &val, *expected_ptr, *new_ptr;
if (__atomic_fetch_add(&val, 1010, __ATOMIC_SEQ_CST) != 1010 || val != 2020)
return 1;
tmp = val;
if (__atomic_fetch_sub(mem, 1010, __ATOMIC_SEQ_CST) != tmp || val != 1010)
return 1;
if (__atomic_sub_fetch(&val, 1010, __ATOMIC_SEQ_CST) != 0 || val != 0)
return 1;
tmp = 3030;
{
unsigned long long expected = 0;
if (!__atomic_compare_exchange_n(mem, &expected, tmp, 0,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ||
val != tmp)
return 1;
}
__atomic_store_n(&val, 4040, __ATOMIC_RELEASE);
if (__atomic_load_n(&val, __ATOMIC_ACQUIRE) != 4040)
return 1;
expected_ptr = &val;
new_ptr = &tmp;
if (!__atomic_compare_exchange_n(&ptr, &expected_ptr, new_ptr, 0,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST))
return 1;
__atomic_thread_fence(__ATOMIC_SEQ_CST);
if (ptr != &tmp)
return 1;
return 0;
}], [ap_cv_atomic_builtins_64=yes], [ap_cv_atomic_builtins_64=no], [ap_cv_atomic_builtins_64=no])])
if test "$ap_cv_atomic_builtins_64" = "yes"; then
AC_DEFINE(HAVE_ATOMIC_BUILTINS64, 1, [Define if compiler provides 64 bit atomic builtins])
fi
])