2
0
mirror of https://github.com/boostorg/atomic.git synced 2026-02-03 08:42:08 +00:00
Commit Graph

76 Commits

Author SHA1 Message Date
Andrey Semashev
5e2e016668 Fixed pointer arithmetics in wait state initialization on reallocation.
Fixes https://github.com/boostorg/atomic/issues/72.
2024-11-21 20:06:41 +03:00
Andrey Semashev
6ee31382b2 Use futex function wrapper on OpenBSD.
Since recent OpenBSD versions have removed syscall(2) interface, use
futex(2) wrapper that was also added along with the SYS_futex syscall.

Closes https://github.com/boostorg/atomic/pull/68.
2024-05-19 03:23:49 +03:00
Andrey Semashev
b91d55150f Added a changelog entry for pause on RISC-V. 2024-01-15 14:46:39 +03:00
Andrey Semashev
6ec7f682f8 Added a note about deprecation of Windows versions prior to 10. 2023-10-08 20:49:09 +03:00
Andrey Semashev
4a9078a7b8 Dropping support for C++03 compilers.
As a result of dependent libraries dropping support for C++03, Boost.Atomic
is no longer able to support C++03 and now requires C++11 as a minimum.

Drop C++03 compilers from the CI and update docs accordingly. No code changes
at this time.
2023-09-02 19:31:10 +03:00
Andrey Semashev
f7735b60a6 Added support for x87 extended double with reduced precision.
On FreeBSD and OpenBSD 32-bit x86 targets are configured to use 53-bit precision
for long double type. The value still uses 80 bits of storage, but the lowest
11 bits of mantissa are zero.

While at it, also added support for 24-bit precision, which can be configured
in x87. Though the platforms where this configuration is used by default are
not known.

Also, when possible, use predefined macros by gcc and compatible compilers and
avoid including standard library header for defining floating point limit macros.

Related to https://github.com/boostorg/atomic/issues/14.
2023-08-22 13:50:45 +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
295afdecd7 Added a note about C++03 deprecation.
Boost libraries that deprecate C++03 support (namely, Boost.Chrono) are not
used in Boost.Atomic implementation, but they are used in tests (indirectly
through Boost.Thread), which means it will become impossible to test
Boost.Atomic when the support is removed.
2023-03-29 02:27:26 +03:00
Andrey Semashev
39a184f68a Mention that atomics are only supposed to work in WB memory. 2023-02-28 12:24:54 +03:00
Andrey Semashev
c277de6b49 Removed atomic<>::storage() and storage_type.
These public members were deprecated since Boost.Atomic 1.73.
2022-12-22 18:32:09 +03:00
Andrey Semashev
2834450fc3 Only use x86 vector insns for stores with memory orders other than seq_cst.
For seq_cst we must issue a memory fence, so in this case use
cmpxchg8b/cmpxchg16b.

Also, optimized 32-bit x86 code path to make the compiler pass the value
to and from the xmm register instead of hardcoding it in asm blocks.
2022-12-22 14:33:25 +03:00
Andrey Semashev
24a41db3e6 Use AVX instructions for 128-bit loads and stores on x86.
Latest edition of SDM explicitly guarantees that any CPU supporting
AVX guarantees atomicity of aligned 128-bit loads and stores using
movdqa and similar instructions. AMD also confirmed this for their
CPUs here:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104688#c10

And also Zhiaoxin:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104688#c20
2022-12-22 14:29:11 +03:00
Andrey Semashev
963b694313 Added a release note for the fixed compilation with MSVC 14.0. 2022-06-04 20:33:27 +03:00
Andrey Semashev
b1cd90dcec Improved endianness checks portability on ARM, AArch32 and AArch64.
When gcc predefined macros are not defined, use Boost.Predef (which also
checks macros defined in the system endian.h header) to detect endianness.
This may help with gcc impostor compilers that do not define built-in
endianness macros.

Closes https://github.com/boostorg/atomic/issues/59.
2022-04-26 11:39:16 +03:00
Andrey Semashev
08a055ec27 Added BOOST_ATOMIC_NO_DARWIN_ULOCK macro.
The new macro disables ulock-based implementation of waiting and notifying
operations on Darwin systems. This may be useful to comply with Apple
App Store requirements.

Closes https://github.com/boostorg/atomic/issues/55.
2022-03-04 22:36:40 +03:00
Andrey Semashev
bf08155d16 Fix compilation for UWP.
UWP does not support APIs related to dynamic symbol binding and dlls.
Disable runtime detection of WaitOnAddress & co. for that target. These
APIs should be enabled at compile time on Windows 8.

Fixes https://github.com/boostorg/atomic/issues/54.
2021-12-15 02:06:11 +03:00
Andrey Semashev
e08957fb1c Changed docs/Jamfile to generate docs in the library subdirectory.
Supposedly, Boost.Atomic docs were generated in the root doc directory
because they were built as part of the boostdoc target. The updated Jamfile
uses boostrelease target instead, which will hopefully move the docs
under libs/atomic/doc.

Also removed unused css and images copying - we have neither in the docs.
The logo image is not used in the docs, only in README.md.
2021-12-08 19:19:22 +03:00
Andrey Semashev
7110e5b739 Silenced bjam warning about unescaped character. 2021-11-19 17:57:13 +03:00
Andrey Semashev
ead065fc47 Added a release note for VS2015 workaround. 2021-11-15 13:28:12 +03:00
Andrey Semashev
4ae987a617 Added a release note for the added workaround for AIX. 2021-10-28 18:15:08 +03:00
Andrey Semashev
e955004915 Mention bit_cast as a requirement for constexpr atomic ctors. 2021-10-12 23:35:55 +03:00
Andrey Semashev
1d4e279d41 Updated the note about clearing padding in unions. 2021-10-12 23:19:14 +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
805e309a29 Fixed discrepancy between always_has_native_wait_notify and caps macros.
When targeting Windows 8, the always_has_native_wait_notify static constant
would be set to false even though the native implementation of waiting
and notifying operations through WaitOnAddress would always be used.

To fix this, moved direct WaitOnAddress & co. usage to public header. This
also requires users to link with synchronization.lib, which is done
automatically on compilers that support auto-linking.

The compiled library still implements runtime detection of WaitOnAddress,
even when building for Windows 8 and later. This allows user's code to
be later compiled for Windows 7 and older and still work. This code is
not used when user's code targets Windows 8 or later.

As part of this refactoring, renamed has_synchronization test and
related CMake variable to better communicate that we're testing for
a library.
2021-10-09 23:40:42 +03:00
Andrey Semashev
d45947a406 [skip ci] Added an advice to avoid resizing memory with IPC ops running. 2021-10-06 14:27:06 +03:00
Andrey Semashev
ffdccceeb1 Added changelog document. 2021-09-26 23:07:49 +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
559eba81af Use dummy atomic instruction instead of mfence for seq_cst fences on x86.
mfence is more expensive on most recent CPUs than a lock-prefixed instruction
on a dummy location, while the latter is sufficient to implement sequential
consistency on x86. Some performance test results are available here:

https://shipilev.net/blog/2014/on-the-fence-with-dependencies/

Also, for seq_cst stores in gcc_atomic backend, use an xchg instead of
mov+mfence, which are generated by gcc versions older than 10.1.

The machinery to detect mfence presence is still left intact just in case
if we need to use this instruction in the future.

Closes https://github.com/boostorg/atomic/issues/36.
2020-06-11 22:32:01 +03:00
Andrey Semashev
e5e96fbc9a Added atomic_unsigned/signed_lock_free typedefs introduced in C++20.
The typedefs indicate the atomic object type for an unsigned/signed
integer that is lock-free and preferably has native support for waiting
and notifying operations.
2020-06-11 13:07:45 +03:00
Andrey Semashev
80cfbfd0de Added implementation of inter-process atomics.
The inter-process atomics have ipc_ prefixes: ipc_atomic, ipc_atomic_ref
and ipc_atomic_flag. These types are similar to their unprefixed counterparts
with the following distinctions:

- The operations are provided with an added precondition that is_lock_free()
  returns true.
- All operations, including waiting/notifying operations, are address-free,
  so the types are suitable for inter-process communication.
- The new has_native_wait_notify() operation and always_has_native_wait_notify
  static constant allow to test if the target platform has native support for
  address-free waiting/notifying operations. If it does not, a generic
  implementation is used based on a busy wait.
- The new set of capability macros added. The macros are named
  BOOST_ATOMIC_HAS_NATIVE_<T>_IPC_WAIT_NOTIFY and indicate whether address-free
  waiting/notifying operations are supported natively for a given type.

Additionally, to unify interface and implementation of different components,
the has_native_wait_notify() operation and always_has_native_wait_notify
static constant were added to non-IPC atomic types as well. Added
BOOST_ATOMIC_HAS_NATIVE_<T>_WAIT_NOTIFY capability macros to indicate
native support for inter-thread waiting/notifying operations.

Also, added is_lock_free() and is_always_lock_free to atomic_flag.

This commit adds implementation, docs and tests.
2020-06-11 13:07:16 +03:00
Andrey Semashev
4b6884d9c9 Added a note explaining the incompatibility between atomic and atomic_ref. 2020-06-08 00:06:21 +03:00
Andrey Semashev
1cd7ba9bc5 Documented value() operation, clarified the limitation of no padding bits.
The value() operation is useful with futexes, but should not be used for
anything else, basically.

The lack of support for types with padding bits is documented more prominently.
The docs do mention that `long double` on x86 is supported though.

Also, added description of the new tests added recently.

Related to https://github.com/boostorg/atomic/issues/34.
2020-06-07 20:28:09 +03:00
Andrey Semashev
d5dc8f185a Added support for build-time configuration of the lock pool size.
The user may define BOOST_ATOMIC_LOCK_POOL_SIZE_LOG2 macro to specify
binary logarithm of the size of the internal lock pool. The macro
only has effect when building Boost.Atomic.
2020-06-03 01:48:48 +03:00
Andrey Semashev
76e25f36a3 Added generic implementation of C++20 waiting/notifying operations.
The generic implementation is based on the lock pool. A list of condition
variables (or waiting futexes) is added per lock. Basically, the lock
pool serves as a global hash table, where each lock represents
a bucket and each wait state is an element. Every wait operation
allocates a wait state keyed on the pointer to the atomic object. Notify
operations look up the wait state by the atomic pointer and notify
the condition variable/futex. The corresponding lock needs to be acquired
to protect the wait state list during all wait/notify operations.

Backends not involving the lock pool are going to be added later.

The implementation of wait operation extends the C++20 definition in that
it returns the newly loaded value instead of void. This allows the caller
to avoid loading the value himself.

The waiting/notifying operations are not address-free. Address-free variants
will be added later.

Added tests for the new operations and refactored existing tests for atomic
operations. Added docs for the new operations.
2020-06-03 01:39:20 +03:00
Andrey Semashev
9cdf02b612 Merge pull request #23 from bazald/develop
Change example documentation for the multi-producer queue to indicate lock-freedom
2020-04-29 18:55:16 +03:00
Andrey Semashev
dd4cb7e540 Nonessential wording fix. 2020-04-01 19:31:22 +03:00
Andrey Semashev
9e26129616 Added a note of caution about object alignment for atomic_ref. 2020-04-01 19:28:38 +03:00
Andrey Semashev
11f3c3eb40 Replaced the term "referred" with "referenced" in the docs.
This is closer to the C++ standard wording regarding atomic_ref.
2020-03-09 19:33:52 +03:00
Andrey Semashev
59ee7c9e9e Removed support for BOOST_ATOMIC_DETAIL_HIGHLIGHT_OP_AND_TEST.
The macro was used to highlight the (op)_and_test methods of atomic<>
that changed the returned value to the opposite in Boost 1.67. The old
behavior was only released in 1.66 and the macro was a means to help
1.66 users to transition to the new releases.

1.67 will have been released 2 years before the upcoming 1.73 release,
in which this macro will be removed.
2020-02-29 23:52:19 +03:00
Andrey Semashev
4336ac66bd Added support for C++20 atomic_flag::test operation.
The operation allows to test whether the flag is in the set state.
Also added tests and docs.
2020-02-26 01:24:54 +03:00
Andrey Semashev
502208b6c5 Removed checks for padding bits in generic atomic_ref specialization.
We currently don't support structs with padding bits, so the checks
are useless. Also, updated docs so that users are not given the idea
that structs with padding bits are supported.
2020-02-26 00:42:15 +03:00
Andrey Semashev
904871c37d Implemented atomic_ref.
This commit adds C++20 atomic_ref implementation, documentation and tests.
2020-02-25 02:00:05 +03:00
Mitchell Keith Bloch
87e38d3c60 Minimally correct the example documentation for the multi-producer queue to indicate lock-freedom rather than wait-freedom since the push function does not appear to satisfy the requirements for wait-freedom. 2019-08-18 18:52:08 -04:00
Andrey Semashev
e16092f473 Updated copyright year. 2018-03-18 01:39:40 +03:00
Andrey Semashev
8d5c592da2 Updated the Limitations section. 2018-02-27 02:20:09 +03:00
Andrey Semashev
b575159f8e Improved the wording of the note re. padding bits in FP types. 2018-02-13 04:09:24 +03:00
Andrey Semashev
edef50f042 Added support for atomic floating point operations.
The support includes:

- The standard fetch_add/fetch_sub operations.
- Extra operations: (fetch_/opaque_)negate, (opaque_)add/sub.
- Extra capability macros: BOOST_ATOMIC_FLOAT/DOUBLE/LONG_DOUBLE_LOCK_FREE.

The atomic operations are currently implemented on top of the integer-based
backends and thus are mostly CAS-based. The CAS operations perform binary
comparisons, and as such have different behavior wrt. special FP values like
NaN and signed zero than normal C++.

The support for floating point types is optional and can be disabled by
defining BOOST_ATOMIC_NO_FLOATING_POINT. This can be useful if on a certain
platform parameters of the floating point types cannot be deduced from the
compiler-defined or system macros (in which case the compilation fails).

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0020r6.html
2018-02-13 03:36:35 +03:00