diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/gcc~13/_005f_005fatomic-builtins.html | |
new repository
Diffstat (limited to 'devdocs/gcc~13/_005f_005fatomic-builtins.html')
| -rw-r--r-- | devdocs/gcc~13/_005f_005fatomic-builtins.html | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/devdocs/gcc~13/_005f_005fatomic-builtins.html b/devdocs/gcc~13/_005f_005fatomic-builtins.html new file mode 100644 index 00000000..0824f12d --- /dev/null +++ b/devdocs/gcc~13/_005f_005fatomic-builtins.html @@ -0,0 +1,90 @@ +<div class="section-level-extent" id="g_t_005f_005fatomic-Builtins"> <div class="nav-panel"> <p> Next: <a href="integer-overflow-builtins" accesskey="n" rel="next">Built-in Functions to Perform Arithmetic with Overflow Checking</a>, Previous: <a href="_005f_005fsync-builtins" accesskey="p" rel="prev">Legacy <code class="code">__sync</code> Built-in Functions for Atomic Memory Access</a>, Up: <a href="c-extensions" accesskey="u" rel="up">Extensions to the C Language Family</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="section" id="Built-in-Functions-for-Memory-Model-Aware-Atomic-Operations"><span>6.55 Built-in Functions for Memory Model Aware Atomic Operations<a class="copiable-link" href="#Built-in-Functions-for-Memory-Model-Aware-Atomic-Operations"> ¶</a></span></h1> <p>The following built-in functions approximately match the requirements for the C++11 memory model. They are all identified by being prefixed with ‘<samp class="samp">__atomic</samp>’ and most are overloaded so that they work with multiple types. </p> <p>These functions are intended to replace the legacy ‘<samp class="samp">__sync</samp>’ builtins. The main difference is that the memory order that is requested is a parameter to the functions. New code should always use the ‘<samp class="samp">__atomic</samp>’ builtins rather than the ‘<samp class="samp">__sync</samp>’ builtins. </p> <p>Note that the ‘<samp class="samp">__atomic</samp>’ builtins assume that programs will conform to the C++11 memory model. In particular, they assume that programs are free of data races. See the C++11 standard for detailed requirements. </p> <p>The ‘<samp class="samp">__atomic</samp>’ builtins can be used with any integral scalar or pointer type that is 1, 2, 4, or 8 bytes in length. 16-byte integral types are also allowed if ‘<samp class="samp">__int128</samp>’ (see <a class="pxref" href="_005f_005fint128">128-bit Integers</a>) is supported by the architecture. </p> <p>The four non-arithmetic functions (load, store, exchange, and compare_exchange) all have a generic version as well. This generic version works on any data type. It uses the lock-free built-in function if the specific data type size makes that possible; otherwise, an external call is left to be resolved at run time. This external call is the same format with the addition of a ‘<samp class="samp">size_t</samp>’ parameter inserted as the first parameter indicating the size of the object being pointed to. All objects must be the same size. </p> <p>There are 6 different memory orders that can be specified. These map to the C++11 memory orders with the same names, see the C++11 standard or the <a class="uref" href="https://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync">GCC wiki on atomic synchronization</a> for detailed definitions. Individual targets may also support additional memory orders for use on specific architectures. Refer to the target documentation for details of these. </p> <p>An atomic operation can both constrain code motion and be mapped to hardware instructions for synchronization between threads (e.g., a fence). To which extent this happens is controlled by the memory orders, which are listed here in approximately ascending order of strength. The description of each memory order is only meant to roughly illustrate the effects and is not a specification; see the C++11 memory model for precise semantics. </p> <dl class="table"> <dt><code class="code">__ATOMIC_RELAXED</code></dt> <dd><p>Implies no inter-thread ordering constraints. </p></dd> <dt><code class="code">__ATOMIC_CONSUME</code></dt> <dd><p>This is currently implemented using the stronger <code class="code">__ATOMIC_ACQUIRE</code> memory order because of a deficiency in C++11’s semantics for <code class="code">memory_order_consume</code>. </p></dd> <dt><code class="code">__ATOMIC_ACQUIRE</code></dt> <dd><p>Creates an inter-thread happens-before constraint from the release (or stronger) semantic store to this acquire load. Can prevent hoisting of code to before the operation. </p></dd> <dt><code class="code">__ATOMIC_RELEASE</code></dt> <dd><p>Creates an inter-thread happens-before constraint to acquire (or stronger) semantic loads that read from this release store. Can prevent sinking of code to after the operation. </p></dd> <dt><code class="code">__ATOMIC_ACQ_REL</code></dt> <dd><p>Combines the effects of both <code class="code">__ATOMIC_ACQUIRE</code> and <code class="code">__ATOMIC_RELEASE</code>. </p></dd> <dt><code class="code">__ATOMIC_SEQ_CST</code></dt> <dd><p>Enforces total ordering with all other <code class="code">__ATOMIC_SEQ_CST</code> operations. </p></dd> </dl> <p>Note that in the C++11 memory model, <em class="emph">fences</em> (e.g., ‘<samp class="samp">__atomic_thread_fence</samp>’) take effect in combination with other atomic operations on specific memory locations (e.g., atomic loads); operations on specific memory locations do not necessarily affect other operations in the same way. </p> <p>Target architectures are encouraged to provide their own patterns for each of the atomic built-in functions. If no target is provided, the original non-memory model set of ‘<samp class="samp">__sync</samp>’ atomic built-in functions are used, along with any required synchronization fences surrounding it in order to achieve the proper behavior. Execution in this case is subject to the same restrictions as those built-in functions. </p> <p>If there is no pattern or mechanism to provide a lock-free instruction sequence, a call is made to an external routine with the same parameters to be resolved at run time. </p> <p>When implementing patterns for these built-in functions, the memory order parameter can be ignored as long as the pattern implements the most restrictive <code class="code">__ATOMIC_SEQ_CST</code> memory order. Any of the other memory orders execute correctly with this memory order but they may not execute as efficiently as they could with a more appropriate implementation of the relaxed requirements. </p> <p>Note that the C++11 standard allows for the memory order parameter to be determined at run time rather than at compile time. These built-in functions map any run-time value to <code class="code">__ATOMIC_SEQ_CST</code> rather than invoke a runtime library call or inline a switch statement. This is standard compliant, safe, and the simplest approach for now. </p> <p>The memory order parameter is a signed int, but only the lower 16 bits are reserved for the memory order. The remainder of the signed int is reserved for target use and should be 0. Use of the predefined atomic values ensures proper usage. </p> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fload_005fn"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_load_n</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fload_005fn"> ¶</a></span> +</dt> <dd> +<p>This built-in function implements an atomic load operation. It returns the contents of <code class="code">*<var class="var">ptr</var></code>. </p> <p>The valid memory order variants are <code class="code">__ATOMIC_RELAXED</code>, <code class="code">__ATOMIC_SEQ_CST</code>, <code class="code">__ATOMIC_ACQUIRE</code>, and <code class="code">__ATOMIC_CONSUME</code>. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fload"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">void</code> <strong class="def-name">__atomic_load</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> *ret, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fload"> ¶</a></span> +</dt> <dd> +<p>This is the generic version of an atomic load. It returns the contents of <code class="code">*<var class="var">ptr</var></code> in <code class="code">*<var class="var">ret</var></code>. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fstore_005fn"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">void</code> <strong class="def-name">__atomic_store_n</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fstore_005fn"> ¶</a></span> +</dt> <dd> +<p>This built-in function implements an atomic store operation. It writes <code class="code"><var class="var">val</var></code> into <code class="code">*<var class="var">ptr</var></code>. </p> <p>The valid memory order variants are <code class="code">__ATOMIC_RELAXED</code>, <code class="code">__ATOMIC_SEQ_CST</code>, and <code class="code">__ATOMIC_RELEASE</code>. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fstore"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">void</code> <strong class="def-name">__atomic_store</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> *val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fstore"> ¶</a></span> +</dt> <dd> +<p>This is the generic version of an atomic store. It stores the value of <code class="code">*<var class="var">val</var></code> into <code class="code">*<var class="var">ptr</var></code>. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fexchange_005fn"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_exchange_n</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fexchange_005fn"> ¶</a></span> +</dt> <dd> +<p>This built-in function implements an atomic exchange operation. It writes <var class="var">val</var> into <code class="code">*<var class="var">ptr</var></code>, and returns the previous contents of <code class="code">*<var class="var">ptr</var></code>. </p> <p>All memory order variants are valid. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fexchange"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">void</code> <strong class="def-name">__atomic_exchange</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> *val, <var class="var">type</var> *ret, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fexchange"> ¶</a></span> +</dt> <dd> +<p>This is the generic version of an atomic exchange. It stores the contents of <code class="code">*<var class="var">val</var></code> into <code class="code">*<var class="var">ptr</var></code>. The original value of <code class="code">*<var class="var">ptr</var></code> is copied into <code class="code">*<var class="var">ret</var></code>. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fcompare_005fexchange_005fn"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">bool</code> <strong class="def-name">__atomic_compare_exchange_n</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> *expected, <var class="var">type</var> desired, bool weak, int success_memorder, int failure_memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fcompare_005fexchange_005fn"> ¶</a></span> +</dt> <dd> +<p>This built-in function implements an atomic compare and exchange operation. This compares the contents of <code class="code">*<var class="var">ptr</var></code> with the contents of <code class="code">*<var class="var">expected</var></code>. If equal, the operation is a <em class="emph">read-modify-write</em> operation that writes <var class="var">desired</var> into <code class="code">*<var class="var">ptr</var></code>. If they are not equal, the operation is a <em class="emph">read</em> and the current contents of <code class="code">*<var class="var">ptr</var></code> are written into <code class="code">*<var class="var">expected</var></code>. <var class="var">weak</var> is <code class="code">true</code> for weak compare_exchange, which may fail spuriously, and <code class="code">false</code> for the strong variation, which never fails spuriously. Many targets only offer the strong variation and ignore the parameter. When in doubt, use the strong variation. </p> <p>If <var class="var">desired</var> is written into <code class="code">*<var class="var">ptr</var></code> then <code class="code">true</code> is returned and memory is affected according to the memory order specified by <var class="var">success_memorder</var>. There are no restrictions on what memory order can be used here. </p> <p>Otherwise, <code class="code">false</code> is returned and memory is affected according to <var class="var">failure_memorder</var>. This memory order cannot be <code class="code">__ATOMIC_RELEASE</code> nor <code class="code">__ATOMIC_ACQ_REL</code>. It also cannot be a stronger order than that specified by <var class="var">success_memorder</var>. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fcompare_005fexchange"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">bool</code> <strong class="def-name">__atomic_compare_exchange</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> *expected, <var class="var">type</var> *desired, bool weak, int success_memorder, int failure_memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fcompare_005fexchange"> ¶</a></span> +</dt> <dd> +<p>This built-in function implements the generic version of <code class="code">__atomic_compare_exchange</code>. The function is virtually identical to <code class="code">__atomic_compare_exchange_n</code>, except the desired value is also a pointer. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fadd_005ffetch"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_add_fetch</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fadd_005ffetch"> ¶</a></span> +</dt> <dt class="deftypefnx def-cmd-deftypefn" id="index-_005f_005fatomic_005fsub_005ffetch"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_sub_fetch</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fsub_005ffetch"> ¶</a></span> +</dt> <dt class="deftypefnx def-cmd-deftypefn" id="index-_005f_005fatomic_005fand_005ffetch"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_and_fetch</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fand_005ffetch"> ¶</a></span> +</dt> <dt class="deftypefnx def-cmd-deftypefn" id="index-_005f_005fatomic_005fxor_005ffetch"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_xor_fetch</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fxor_005ffetch"> ¶</a></span> +</dt> <dt class="deftypefnx def-cmd-deftypefn" id="index-_005f_005fatomic_005for_005ffetch"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_or_fetch</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005for_005ffetch"> ¶</a></span> +</dt> <dt class="deftypefnx def-cmd-deftypefn" id="index-_005f_005fatomic_005fnand_005ffetch"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_nand_fetch</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fnand_005ffetch"> ¶</a></span> +</dt> <dd> +<p>These built-in functions perform the operation suggested by the name, and return the result of the operation. Operations on pointer arguments are performed as if the operands were of the <code class="code">uintptr_t</code> type. That is, they are not scaled by the size of the type to which the pointer points. </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">{ *ptr <var class="var">op</var>= val; return *ptr; } +{ *ptr = ~(*ptr & val); return *ptr; } // nand</pre> +</div> <p>The object pointed to by the first argument must be of integer or pointer type. It must not be a boolean type. All memory orders are valid. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005ffetch_005fadd"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_fetch_add</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005ffetch_005fadd"> ¶</a></span> +</dt> <dt class="deftypefnx def-cmd-deftypefn" id="index-_005f_005fatomic_005ffetch_005fsub"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_fetch_sub</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005ffetch_005fsub"> ¶</a></span> +</dt> <dt class="deftypefnx def-cmd-deftypefn" id="index-_005f_005fatomic_005ffetch_005fand"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_fetch_and</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005ffetch_005fand"> ¶</a></span> +</dt> <dt class="deftypefnx def-cmd-deftypefn" id="index-_005f_005fatomic_005ffetch_005fxor"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_fetch_xor</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005ffetch_005fxor"> ¶</a></span> +</dt> <dt class="deftypefnx def-cmd-deftypefn" id="index-_005f_005fatomic_005ffetch_005for"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_fetch_or</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005ffetch_005for"> ¶</a></span> +</dt> <dt class="deftypefnx def-cmd-deftypefn" id="index-_005f_005fatomic_005ffetch_005fnand"> +<span class="category-def">Built-in Function: </span><span><code class="def-type"><var class="var">type</var></code> <strong class="def-name">__atomic_fetch_nand</strong> <code class="def-code-arguments">(<var class="var">type</var> *ptr, <var class="var">type</var> val, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005ffetch_005fnand"> ¶</a></span> +</dt> <dd> +<p>These built-in functions perform the operation suggested by the name, and return the value that had previously been in <code class="code">*<var class="var">ptr</var></code>. Operations on pointer arguments are performed as if the operands were of the <code class="code">uintptr_t</code> type. That is, they are not scaled by the size of the type to which the pointer points. </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">{ tmp = *ptr; *ptr <var class="var">op</var>= val; return tmp; } +{ tmp = *ptr; *ptr = ~(*ptr & val); return tmp; } // nand</pre> +</div> <p>The same constraints on arguments apply as for the corresponding <code class="code">__atomic_op_fetch</code> built-in functions. All memory orders are valid. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005ftest_005fand_005fset"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">bool</code> <strong class="def-name">__atomic_test_and_set</strong> <code class="def-code-arguments">(void *ptr, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005ftest_005fand_005fset"> ¶</a></span> +</dt> <dd> <p>This built-in function performs an atomic test-and-set operation on the byte at <code class="code">*<var class="var">ptr</var></code>. The byte is set to some implementation defined nonzero “set” value and the return value is <code class="code">true</code> if and only if the previous contents were “set”. It should be only used for operands of type <code class="code">bool</code> or <code class="code">char</code>. For other types only part of the value may be set. </p> <p>All memory orders are valid. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fclear"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">void</code> <strong class="def-name">__atomic_clear</strong> <code class="def-code-arguments">(bool *ptr, int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fclear"> ¶</a></span> +</dt> <dd> <p>This built-in function performs an atomic clear operation on <code class="code">*<var class="var">ptr</var></code>. After the operation, <code class="code">*<var class="var">ptr</var></code> contains 0. It should be only used for operands of type <code class="code">bool</code> or <code class="code">char</code> and in conjunction with <code class="code">__atomic_test_and_set</code>. For other types it may only clear partially. If the type is not <code class="code">bool</code> prefer using <code class="code">__atomic_store</code>. </p> <p>The valid memory order variants are <code class="code">__ATOMIC_RELAXED</code>, <code class="code">__ATOMIC_SEQ_CST</code>, and <code class="code">__ATOMIC_RELEASE</code>. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fthread_005ffence"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">void</code> <strong class="def-name">__atomic_thread_fence</strong> <code class="def-code-arguments">(int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fthread_005ffence"> ¶</a></span> +</dt> <dd> <p>This built-in function acts as a synchronization fence between threads based on the specified memory order. </p> <p>All memory orders are valid. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fsignal_005ffence"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">void</code> <strong class="def-name">__atomic_signal_fence</strong> <code class="def-code-arguments">(int memorder)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fsignal_005ffence"> ¶</a></span> +</dt> <dd> <p>This built-in function acts as a synchronization fence between a thread and signal handlers based in the same thread. </p> <p>All memory orders are valid. </p> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005falways_005flock_005ffree"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">bool</code> <strong class="def-name">__atomic_always_lock_free</strong> <code class="def-code-arguments">(size_t size, void *ptr)</code><a class="copiable-link" href="#index-_005f_005fatomic_005falways_005flock_005ffree"> ¶</a></span> +</dt> <dd> <p>This built-in function returns <code class="code">true</code> if objects of <var class="var">size</var> bytes always generate lock-free atomic instructions for the target architecture. <var class="var">size</var> must resolve to a compile-time constant and the result also resolves to a compile-time constant. </p> <p><var class="var">ptr</var> is an optional pointer to the object that may be used to determine alignment. A value of 0 indicates typical alignment should be used. The compiler may also ignore this parameter. </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">if (__atomic_always_lock_free (sizeof (long long), 0))</pre> +</div> </dd> +</dl> <dl class="first-deftypefn"> <dt class="deftypefn" id="index-_005f_005fatomic_005fis_005flock_005ffree"> +<span class="category-def">Built-in Function: </span><span><code class="def-type">bool</code> <strong class="def-name">__atomic_is_lock_free</strong> <code class="def-code-arguments">(size_t size, void *ptr)</code><a class="copiable-link" href="#index-_005f_005fatomic_005fis_005flock_005ffree"> ¶</a></span> +</dt> <dd> <p>This built-in function returns <code class="code">true</code> if objects of <var class="var">size</var> bytes always generate lock-free atomic instructions for the target architecture. If the built-in function is not known to be lock-free, a call is made to a runtime routine named <code class="code">__atomic_is_lock_free</code>. </p> <p><var class="var">ptr</var> is an optional pointer to the object that may be used to determine alignment. A value of 0 indicates typical alignment should be used. The compiler may also ignore this parameter. </p> +</dd> +</dl> </div> <div class="nav-panel"> <p> Next: <a href="integer-overflow-builtins">Built-in Functions to Perform Arithmetic with Overflow Checking</a>, Previous: <a href="_005f_005fsync-builtins">Legacy <code class="code">__sync</code> Built-in Functions for Atomic Memory Access</a>, Up: <a href="c-extensions">Extensions to the C Language Family</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution"> + <p class="_attribution-p"> + © Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br> + <a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/_005f_005fatomic-Builtins.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/_005f_005fatomic-Builtins.html</a> + </p> +</div> |
