2
0
mirror of https://github.com/boostorg/atomic.git synced 2026-01-19 16:12:09 +00:00

129 Commits

Author SHA1 Message Date
Andrey Semashev
1464ef7c2a Fix b2 import search path for configure-time checks.
Added a missing import-search directive to config/Jamfile so that
atomic-arch-config.jam is found when configure-time checks are invoked
from tests. This allows us to enable the type_traits check for tests.
2025-06-18 20:32:30 +03:00
Andrey Semashev
f3b61da9c0 Move cxx11_hdr_ratio requirement to from tests the library.
We no longer include <ratio> in tests, but we do include it in the
library headers.
2025-06-18 19:44:17 +03:00
Andrey Semashev
cbe50fe500 Restore compatibility with older gcc versions.
Added is_trivially_copyable and is_trivially_default_constructible type
traits that rely on the non-standard type traits available in libstdc++
from gcc 4.8 and 4.9.

Rather than requiring cxx11_hdr_type_traits in the library and test
requirements, use a more limited test that checks only the type traits
we use in Boost.Atomic.

Similarly, downgrade the requirement of C++ unrestricted unions to
unions with members that have non-trivial default constructors.

Remove the requirements of alignas and alignof, since those are not
mandatory for now.

Closes https://github.com/boostorg/atomic/issues/74.
2025-06-18 19:09:03 +03:00
Andrey Semashev
ff2574cd03 Enable bitwise operations for enumerations.
This is a Boost.Atomic extension over std::atomic.

Bitwise operations can be useful if the enumeration is used to implement
a bit mask or a set of flags. Without these operations, users have to
manually perform conversions between the enum type and the underlying
type, which can be tedious.

There are caveats with enums with non-fixed underlying type, but the
convenience outweighs the potential pitfalls.
2025-06-13 00:24:13 +03:00
Andrey Semashev
1fa02d93f0 Removed BOOST_ATOMIC_NO_ATOMIC_FLAG_INIT macro definition.
Since the library now requires C++11, BOOST_ATOMIC_FLAG_INIT is always
supported.
2025-06-12 00:54:03 +03:00
Andrey Semashev
fc751f1db6 Retry notify_one_test if the second thread receives value2.
Occasionally, notify_one_test fails because the second thread receives
value2 instead of value3, even though the wakeup delay check passes.
This typically happens on one of the VM runners, so it is possible
there is some weird timing issue, when the thread gets woken up spuriously,
before the atomic value is updated, but the recorded wait time ends
up just above the expected waiting duration. Just retry the test
in this case.

Also use seq_cst in wait tests consistently instead of release on
stores and seq_cst on waits.
2025-06-11 04:36:52 +03:00
Andrey Semashev
1dbff0108a Added header-only dependencies to tests Jamfile. 2025-06-11 04:26:11 +03:00
Andrey Semashev
2c0300f074 Switch to <cstdint> header. 2025-06-11 01:01:35 +03:00
Andrey Semashev
ab59271bdf Remove some of the pre-C++11 workarounds.
Replaced C++11 emulation macros with proper keywords, replaced typedefs
with using-style type aliases, removed type traits shims that are no
longer needed.
2025-06-11 01:00:52 +03:00
Andrey Semashev
37c2b67324 Added support for MSVC ARM64EC target.
ARM64EC is similar to ARM64 in that the binary will run natively on
ARM64 CPUs and therefore supports all ARM64 intrinsics. The difference
is that it also supports AMD64 intrinsics (and therefore defines _M_AMD64
and _M_X64), which will be emulated by an implicitly linked library.
ARM64EC also changes ABI compared to ARM64, but it doesn't affect
Boost.Atomic.

Changed predefined macro checks in order to use msvc_arm backend for
ARM64EC instead of msvc_x86. The benefit is that msvc_arm uses memory
order-aware intrinsics instead of the full-fence ones on x86. The
downside is that 128-bit atomics won't be available (for now).

Also define BOOST_ATOMIC_DETAIL_INT_FP_ENDIAN_MATCH for ARM/ARM64
on Windows.
2025-06-09 02:22:34 +03:00
Andrey Semashev
03eb376616 Renamed smt_pause to thread_pause.
Although smt_pause matches the equivalent global function on Solaris and
some BSD systems both in name and behavior, this naming clash may cause
confusion and ambiguities in users' code that imports boost::atomics
namespace into their scope and calls smt_pause unqualified. Better
avoid these issues and pick a different name.

Add a simple test for thread_pause, which only tests that the operation
compiles and executes.

Also include the recently added headers in the global atomic.hpp.
2025-06-08 23:19:36 +03:00
Andrey Semashev
8454d8a089 Replaced test_clock with std::chrono::steady_clock in tests.
This uses std::chrono::steady_clock universally in tests where monotonic
clock is needed. On Windows, hopefully this will resolve the time mismatches
between wakeups and externally measures times. Given that we use absolute
timeouts for sleeps, hopefully, this will also not reintroduce problems
that were originally worked around by test_clock.
2025-06-08 15:58:24 +03:00
Andrey Semashev
3a6abd10c1 Added tests for timed waiting operations. 2025-06-08 14:50:34 +03:00
Andrey Semashev
b36b040f3f Removed chrono workarounds for older compilers. 2025-06-08 04:37:51 +03:00
Andrey Semashev
bbe9234f8f Use absolute timeouts for sleeping in wait test helpers.
This may improve the precision of timing of thread wakeups.
2025-06-08 04:37:51 +03:00
Andrey Semashev
39f8c3213d Use GetTickCount64 unconditionally in tests on Windows. 2025-06-08 04:37:51 +03:00
Andrey Semashev
bafa2665aa Require more C++11 support from the compiler.
We are going to use more C++11 features unconditionally, so add more
requirements in the build files. Don't straight require cxx11 in the
Jamfile as this eliminates all versions of MSVC from the builds.

Also remove older compilers that don't support enough of C++11 from CI.
2025-06-08 04:35:46 +03:00
Andrey Semashev
5e0ce516fb Moved backoff_dummy to the stacks.
This avoids TSAN warnings triggered by concurrent writes to the global
variable, even though there is no race (as noone reads the variable).
2025-02-23 00:30:19 +03:00
Andrey Semashev
de94875920 Suppress TSAN for intentionally racy functions in tests. 2025-02-23 00:30:19 +03:00
Andrey Semashev
b202228311 Added support for running tests in CMake.
Related to https://github.com/boostorg/atomic/issues/71.
2024-10-19 17:29:55 +03:00
Andrey Semashev
d5914e357f Work around MSVC warnings in test code. 2024-10-19 16:06:48 +03:00
Andrey Semashev
aebe9d585c Switched tests to std::thread and std::chrono.
This removes dependencies on Boost.Thread and Boost.Chrono, as well as
their dependencies and potentially allows to test more compilers. In particular,
this removes the dependency on Boost.Lexical cast, which no longer compiles
with gcc 4.6 and 4.7.
2023-09-03 22:11:23 +03:00
Andrey Semashev
8f480549ee Use C++11 static_assert.
This removes the dependency on Boost.StaticAssert.
2023-09-03 22:03:19 +03:00
Andrey Semashev
474e125ab6 Fixed compilation of atomic_ref for const-qualified types.
Fixes https://github.com/boostorg/atomic/issues/62.
2023-04-29 15:11:25 +03:00
Andrey Semashev
195d0b9854 Added tests for relaxed loads and stores.
This will involve different branches of code in some asm-based backends.
2022-12-21 21:03:50 +03:00
Andrey Semashev
e44ef5fa3d Ported to BOOST_NO_CXX17_DEDUCTION_GUIDES from Boost.Config. 2022-06-17 01:16:55 +03:00
Andrey Semashev
a172675470 Added source directories to include directories.
This fixes compilation on systems where the compiler does not resolve
includes relative to the current source file directory.

Fixes https://github.com/boostorg/atomic/issues/56.
Closes https://github.com/boostorg/atomic/pull/57.
2022-03-07 01:21:19 +03:00
Andrey Semashev
f4037199b7 Removed names of unused parameters to silence warnings. 2021-10-27 12:04:07 +03:00
Andrey Semashev
8a7aaa543d Make atomic default ctors value initialize the contained object.
This is in line with the C++20 change that requires the default constructor
of std::atomic to value initialize the atomic object.

Also, use is_nothrow_default_constructible to properly deduce noexceptness
of the default constructors of atomics.
2021-10-12 20:36:11 +03:00
Andrey Semashev
2211fee1d4 Added bitwise_cast implementation based on bit_cast intrinsics.
This allows to mark bitwise_cast constexpr when the conditions to use
bit_cast are met:

 - both source and target types have the same size, and
 - the source type has no padding bits.

The latter is checked using has_unique_object_representations trait, which
we also implement using intrinsics when not available in the standard
library.

This allows atomic constructors to become constexpr for structs and floating
point types with no padding and whose size matches the atomic storage size.
2021-10-12 18:55:13 +03:00
Andrey Semashev
746ea2649b Added support for types with padding. Made atomic ctors for enums constexpr.
Use __builtin_clear_padding and __builtin_zero_non_value_bits that were
introduced in gcc 11 and MSVC 19.27 to clear the padding bits in atomic
types. The intrinsics are used in bitwise_cast and atomic reference
constructors.

Also, separated atomic impl specializations for enums to allow using
static_cast to convert values to storage. This in turn allows to
relax compiler requirements to mark atomic constructors constexpr.

Updated docs and added tests for structs with padding and constexpr
atomic constructors.
2021-10-11 18:05:06 +03:00
Andrey Semashev
ef4dedb031 Added tests for HAS_NATIVE_WAIT_NOTIFY macros and static constants. 2021-10-09 21:22:20 +03:00
Andrey Semashev
cbf5ae1ad2 Allocate IPC atomic objects in dynamic memory instead of the stack.
This works around spurious test failures on Mac OS as the notifying operation
sometimes fails with ENOENT. Presumably, the OS sometimes invalidates the
internal identification of the stack memory region, which makes __ulock_wake
fail to find the ulock object that other threads are blocked on.

By using dynamic memory we (hopefully) are using a location in a normal mapped
memory region that should not be mangled by the OS. Ideally, we would use
process-shared memory for this test, but that makes it more difficult to make
it portable and runnable in parallel. Dynamic local memory should do for now.
2021-09-26 19:54:01 +03:00
Andrey Semashev
a548b3c15c Added template deduction guides and factory functions for atomic refs. 2021-06-16 02:22:40 +03:00
Andrey Semashev
e9374cb8db Disabled gcc and clang warnings caused by Boost.Preprocessor.
Boost.Preprocessor uses variadic macros and empty macro arguments
even in C++03 mode, which makes gcc and clang emit lots of warnings.
2021-02-01 01:29:43 +03:00
Andrey Semashev
ea5911a413 Added tests for arithmetic and bitwise ops with immediate constants.
This test verifies arithmetic and bitwise (logic) operations with
immediate constant arguments, which may affect instruction choice
in the operations. In particular, the test verifies that bug
https://github.com/boostorg/atomic/issues/41 is fixed.
2020-11-20 13:58:16 +03:00
Andrey Semashev
a40aa9ba6c Implemented SSE2 and SSE4.1 versions of address lookup algorithms. 2020-09-07 16:57:22 +03:00
Andrey Semashev
9e9d1f4398 Added AArch32 and AArch64 gcc asm-based backends.
This is the second iteration of the backends, which were both tested
on a QEMU VM and did not show any test failures. The essential difference
from the first version is that in AArch64 we now initialize the success flag
in the asm blocks in compare_exchange operations rather than relying on
compiler initializing it before passing into the asm block as an in-out
parameter. Apparently, this sometimes didn't work for some reason, which
made compare_exchange_strong return incorrect value, which broke futex-based
mutexes in the lock pool.

The above change was also applied to AArch32, along with minor corrections
in the asm blocks constraints.
2020-06-24 21:52:52 +03:00
Andrey Semashev
fd2326cf4d Added a check in notify_one tests if the first thread wakes up too late.
In that case the first thread may receive the value3 instead of value2.
2020-06-24 14:53:27 +03:00
Andrey Semashev
5ec2265754 Removed AArch32 and AArch64 gcc asm-based backends.
The backends will be moved to a separate branch for testing.
2020-06-24 14:41:33 +03:00
Andrey Semashev
a247342a13 Added support for newer gcc versions and ARMv8 AArch32 in lockfree test. 2020-06-23 22:55:14 +03:00
Andrey Semashev
e5bb7eca93 Corrected check for cmpxchg16b availability in lockfree test. 2020-06-23 21:57:18 +03:00
Andrey Semashev
06dcdf26c6 Added a configure check to test if synchronization.lib exists.
We need to explicitly link with synchronization.lib when the
WaitOnAddress API is enabled at compile time for ARM targets. Since
this library is only available on newer Windows SDKs, we have to perform
a configure check for whether it is available.
2020-06-21 19:07:28 +03:00
Andrey Semashev
b02b59fd3a Separated arch-specific core and fence operations to new ops structures.
The old operations template is replaced with core_operations, which falls
back to core_arch_operations, which falls back to core_operations_emulated.

The core_operations layer is intended for more or less architecture-neutral
backends, like the one based on gcc __atomic* intrinsics. It may fall back
to core_arch_operations where it is not supported by the compiler or where
the latter is more optimal. For example, where gcc does not implement 128-bit
atomic operations via __atomic* intrinsics, we support them in the
core_arch_operations backend, which uses inline assembler blocks.

The old emulated_operations template is largely unchanged and was renamed to
core_operations_emulated for naming consistency. All other operation templates
were also renamed for consistency (e.g. generic_wait_operations ->
wait_operations_generic).

Fence operations have been extracted to a separate set of structures:
fence_operations, fence_arch_opereations and fence_operations_emulated. These
are similar to the core operations described above. This structuring also
allows to fall back from fence_operations to fence_arch_opereations when
the latter is more optimal.

The net result of these changes is that 128-bit and 64-bit atomic operations
should now be consistently supported on all architectures that support them.
Previously, only x86 was supported via local hacks for gcc and clang.
2020-06-21 19:07:20 +03:00
Andrey Semashev
651dfd4afb Added gcc asm-based backend for AArch64.
The backend implements core and extra atomic operations using gcc asm blocks.
The implementation supports extensions added in ARMv8.1 and ARMv8.3. It supports
both little and big endian targets.

Currently, the code has not been tested on real hardware. It has been tested
on a QEMU VM.
2020-06-18 12:46:03 +00:00
Andrey Semashev
0cf7964f78 Another workaround for IPC notify_one failures on Windows.
The previous change to increase the delay didn't help, so we're instead
changing the expectation - the first woken thread is allowed to receive
value3 on wake up.
2020-06-14 19:12:33 +03:00
Andrey Semashev
3de4c6c865 Increase delay between notifications in IPC notify_one test.
Occasionally, IPC notify_one test fails on Windows because the first
of the woken threads receives value3 from wait(). This is possible if
the thread lingers in wait() for some reason. Increase the delay
before the second notification slightly to reduce the likelihood
of this happening.
2020-06-14 18:10:30 +03:00
Andrey Semashev
3929919495 Implement a special test_clock for Windows.
The implementation uses GetTickCount/GetTickCount64 internally,
which is a steady and sufficiently low precision time source.

We need the clock to have relatively low precision so that wait
tests don't fail spuriously because the blocked threads wake up
too soon, according to more precise clocks.

boost::chrono::system_clock currently has an acceptably low precision,
but it is not a steady clock.
2020-06-12 13:32:32 +03:00
Andrey Semashev
72c87ca51b Use a lower resolution clock on Windows to reduce spurious test failures. 2020-06-12 03:24:29 +03:00
Andrey Semashev
1b8ec1700b Reworked IPC atomic tests to check for the is_always_lockfree property.
Checking for the capability macros is not good enough because ipc_atomic_ref
can be not lock-free even when the macro (and ipc_atomic) indicates lock-free.

We now check the is_always_lockfree property to decide whether to run or skip
tests for a given IPC atomic type.

Also, made struct_3_bytes output more informative.
2020-06-12 01:58:12 +03:00