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

47 Commits

Author SHA1 Message Date
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
Andrey Semashev
92c57ac1e4 Added atomic operations that return the result of the operation.
These operations are useful for two reasons. First, they are needed by
atomic<> interface as the pre-increment/decrement and add/subtract operators
need to perform the corresponding arithmetics and return the actual result while
not exhibiting UB in case of overflow. This means that the operation must be
performed on the unsigned storage type in the backend. Second, the (op)_and_test
operations on ARM and PowerPC can be implemented in a more generic way on top of
the operations that return the result. And since we have those operations
internally, why not expose them to users.

Added tests and docs for the new operations. Also, added docs for the recently
added scoped names of the memory_order enum values.

Also, added a specialized "emulated" backend for the extra operations. This
backend makes better use of the fact that the operations are lock-protected
by avoiding any CAS-based loops.
2018-02-11 00:56:23 +03:00
Andrey Semashev
9fd085c59f Added negate_and_test and complement_and_test ops.
As the names suggest, the methods perform the corresponding operation and test
if the result is not zero.

Also, for the emulated fetch_complement, take care of integral promotion, which
could mess up the storage bits that were not part of the value on backends
where the storage is larger than the value. This could in turn break CAS on
the atomic value as it compares the whole storage.
2018-02-04 00:13:27 +03:00
Andrey Semashev
b24cea0af1 Changed the result of (op)_and_test operations to the opposite.
This makes the result of (op)_and_test more consistent with other
methods such as test_and_set and bit_test_and_set, as well as the
methods used in the C++ standard library.

This is a breaking change. The users are able to define
BOOST_ATOMIC_HIGHLIGHT_OP_AND_TEST macro to generate warnings on each
use of the changed functions. This will help users to port from Boost
1.66 to newer Boost releases.

More info at:

https://github.com/boostorg/atomic/issues/11
http://boost.2283326.n4.nabble.com/atomic-op-and-test-naming-
tc4701445.html
2018-01-28 20:50:12 +03:00
Andrey Semashev
de22c6a203 Added a link to a gcc bug in the comment about consume/acquire MO. 2017-09-20 13:50:33 +03:00
Andrey Semashev
23d5770bde Minor docs formatting correction. 2017-08-06 22:09:41 +03:00
Andrey Semashev
b23afe4b0c Added docs for atomic_flag. 2017-08-06 22:04:26 +03:00
Andrey Semashev
4467cfbd3b Documented the extra operations added as an extension of Boost.Atomic.
Also made a few wording corrections and added is_always_lock_free and
a section about atomic<> typedefs. Clarified the status quo regarding
memory_order_consume. Removed the obsolete preudo-header for doxygen
that was not used for docs (if we want doxygen, it's better to
add comments to the real headers anyway).
2017-07-19 22:05:20 +03:00
Andrey Semashev
5b30e196a6 Added is_always_lock_free static constant from C++17. 2016-10-13 15:59:22 +03:00
Rene Rivera
019610574b Add, and update, documentation build targets. 2016-10-10 11:39:47 -05:00
Andrey Semashev
cc9cff37af Documented BOOST_ATOMIC_NO_CMPXCHG8B and BOOST_ATOMIC_NO_MFENCE config macros. 2016-09-15 01:19:52 +03:00
Andrey Semashev
ffe7710a90 Added a boostdoc target to unify Boost release docs building. 2016-01-06 21:04:08 +03:00
Andrey Semashev
4dee330229 Added support for types with non-trivial default constructors. 2014-07-07 22:40:41 +04:00
Andrey Semashev
560e3c0465 Clarified the requirements on the types compatible with boost::atomic. 2014-06-10 00:21:31 +04:00
Andrey Semashev
7fcb3b18b0 #9527. Fixed a typo in the docs. 2014-05-17 22:06:27 +04:00
Andrey Semashev
b80d0ebe36 Documented the BOOST_ATOMIC_NO_ATOMIC_FLAG_INIT macro. 2014-05-17 20:07:52 +04:00
Andrey Semashev
00c21f9978 Documented new feature test and configuration macros. Fixed disabled gcc atomic backend. 2014-05-17 19:20:51 +04:00
Andrey Semashev
44e9f3c1b7 Added a readme and a logo. 2014-01-19 18:13:36 +04:00
Andrey Semashev
88eb902af7 More docs updates.
[SVN r84803]
2013-06-16 13:55:00 +00:00
Andrey Semashev
5f9abc8544 Added docs for atomicity detection macros.
[SVN r84802]
2013-06-16 13:46:39 +00:00
Tim Blechmann
a6b599b6bb atomic: fix example code
patch by gregor jasny

[SVN r82361]
2013-01-05 14:54:40 +00:00
Tim Blechmann
982dc948e3 atomic: fix typos
fixes #7804

[SVN r82072]
2012-12-18 09:43:23 +00:00
Andrey Semashev
39760bdd91 Updated reference to platform.hpp according to rearranged header layout.
[SVN r81933]
2012-12-14 11:32:31 +00:00
Tim Blechmann
8622f33f85 atomic: integrate documentation
[SVN r81757]
2012-12-07 14:52:41 +00:00
Tim Blechmann
be1524ea4e atomic: update documentation
[SVN r81737]
2012-12-06 12:35:42 +00:00
Helge Bahmann
71564c97cf Add missing copyright and licence notices
Add missing notices to various files to make clear they are distributable
under the boost licence.


[SVN r80527]
2012-09-14 19:12:13 +00:00
Helge Bahmann
131b70c1fa atomic: initial import
[SVN r79348]
2012-07-08 11:21:45 +00:00