Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

412 lines
22KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  20. <title>__atomic Builtins (Using the GNU Compiler Collection (GCC))</title>
  21. <meta name="description" content="__atomic Builtins (Using the GNU Compiler Collection (GCC))">
  22. <meta name="keywords" content="__atomic Builtins (Using the GNU Compiler Collection (GCC))">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="C-Extensions.html#C-Extensions" rel="up" title="C Extensions">
  30. <link href="Integer-Overflow-Builtins.html#Integer-Overflow-Builtins" rel="next" title="Integer Overflow Builtins">
  31. <link href="_005f_005fsync-Builtins.html#g_t_005f_005fsync-Builtins" rel="prev" title="__sync Builtins">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.indentedblock {margin-right: 0em}
  36. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  37. blockquote.smallquotation {font-size: smaller}
  38. div.display {margin-left: 3.2em}
  39. div.example {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style: oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nolinebreak {white-space: nowrap}
  54. span.roman {font-family: initial; font-weight: normal}
  55. span.sansserif {font-family: sans-serif; font-weight: normal}
  56. ul.no-bullet {list-style: none}
  57. -->
  58. </style>
  59. </head>
  60. <body lang="en">
  61. <a name="g_t_005f_005fatomic-Builtins"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Integer-Overflow-Builtins.html#Integer-Overflow-Builtins" accesskey="n" rel="next">Integer Overflow Builtins</a>, Previous: <a href="_005f_005fsync-Builtins.html#g_t_005f_005fsync-Builtins" accesskey="p" rel="prev">__sync Builtins</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  65. </div>
  66. <hr>
  67. <a name="Built_002din-Functions-for-Memory-Model-Aware-Atomic-Operations"></a>
  68. <h3 class="section">6.55 Built-in Functions for Memory Model Aware Atomic Operations</h3>
  69. <p>The following built-in functions approximately match the requirements
  70. for the C++11 memory model. They are all
  71. identified by being prefixed with &lsquo;<samp>__atomic</samp>&rsquo; and most are
  72. overloaded so that they work with multiple types.
  73. </p>
  74. <p>These functions are intended to replace the legacy &lsquo;<samp>__sync</samp>&rsquo;
  75. builtins. The main difference is that the memory order that is requested
  76. is a parameter to the functions. New code should always use the
  77. &lsquo;<samp>__atomic</samp>&rsquo; builtins rather than the &lsquo;<samp>__sync</samp>&rsquo; builtins.
  78. </p>
  79. <p>Note that the &lsquo;<samp>__atomic</samp>&rsquo; builtins assume that programs will
  80. conform to the C++11 memory model. In particular, they assume
  81. that programs are free of data races. See the C++11 standard for
  82. detailed requirements.
  83. </p>
  84. <p>The &lsquo;<samp>__atomic</samp>&rsquo; builtins can be used with any integral scalar or
  85. pointer type that is 1, 2, 4, or 8 bytes in length. 16-byte integral
  86. types are also allowed if &lsquo;<samp>__int128</samp>&rsquo; (see <a href="_005f_005fint128.html#g_t_005f_005fint128">__int128</a>) is
  87. supported by the architecture.
  88. </p>
  89. <p>The four non-arithmetic functions (load, store, exchange, and
  90. compare_exchange) all have a generic version as well. This generic
  91. version works on any data type. It uses the lock-free built-in function
  92. if the specific data type size makes that possible; otherwise, an
  93. external call is left to be resolved at run time. This external call is
  94. the same format with the addition of a &lsquo;<samp>size_t</samp>&rsquo; parameter inserted
  95. as the first parameter indicating the size of the object being pointed to.
  96. All objects must be the same size.
  97. </p>
  98. <p>There are 6 different memory orders that can be specified. These map
  99. to the C++11 memory orders with the same names, see the C++11 standard
  100. or the <a href="http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync">GCC wiki
  101. on atomic synchronization</a> for detailed definitions. Individual
  102. targets may also support additional memory orders for use on specific
  103. architectures. Refer to the target documentation for details of
  104. these.
  105. </p>
  106. <p>An atomic operation can both constrain code motion and
  107. be mapped to hardware instructions for synchronization between threads
  108. (e.g., a fence). To which extent this happens is controlled by the
  109. memory orders, which are listed here in approximately ascending order of
  110. strength. The description of each memory order is only meant to roughly
  111. illustrate the effects and is not a specification; see the C++11
  112. memory model for precise semantics.
  113. </p>
  114. <dl compact="compact">
  115. <dt><code>__ATOMIC_RELAXED</code></dt>
  116. <dd><p>Implies no inter-thread ordering constraints.
  117. </p></dd>
  118. <dt><code>__ATOMIC_CONSUME</code></dt>
  119. <dd><p>This is currently implemented using the stronger <code>__ATOMIC_ACQUIRE</code>
  120. memory order because of a deficiency in C++11&rsquo;s semantics for
  121. <code>memory_order_consume</code>.
  122. </p></dd>
  123. <dt><code>__ATOMIC_ACQUIRE</code></dt>
  124. <dd><p>Creates an inter-thread happens-before constraint from the release (or
  125. stronger) semantic store to this acquire load. Can prevent hoisting
  126. of code to before the operation.
  127. </p></dd>
  128. <dt><code>__ATOMIC_RELEASE</code></dt>
  129. <dd><p>Creates an inter-thread happens-before constraint to acquire (or stronger)
  130. semantic loads that read from this release store. Can prevent sinking
  131. of code to after the operation.
  132. </p></dd>
  133. <dt><code>__ATOMIC_ACQ_REL</code></dt>
  134. <dd><p>Combines the effects of both <code>__ATOMIC_ACQUIRE</code> and
  135. <code>__ATOMIC_RELEASE</code>.
  136. </p></dd>
  137. <dt><code>__ATOMIC_SEQ_CST</code></dt>
  138. <dd><p>Enforces total ordering with all other <code>__ATOMIC_SEQ_CST</code> operations.
  139. </p></dd>
  140. </dl>
  141. <p>Note that in the C++11 memory model, <em>fences</em> (e.g.,
  142. &lsquo;<samp>__atomic_thread_fence</samp>&rsquo;) take effect in combination with other
  143. atomic operations on specific memory locations (e.g., atomic loads);
  144. operations on specific memory locations do not necessarily affect other
  145. operations in the same way.
  146. </p>
  147. <p>Target architectures are encouraged to provide their own patterns for
  148. each of the atomic built-in functions. If no target is provided, the original
  149. non-memory model set of &lsquo;<samp>__sync</samp>&rsquo; atomic built-in functions are
  150. used, along with any required synchronization fences surrounding it in
  151. order to achieve the proper behavior. Execution in this case is subject
  152. to the same restrictions as those built-in functions.
  153. </p>
  154. <p>If there is no pattern or mechanism to provide a lock-free instruction
  155. sequence, a call is made to an external routine with the same parameters
  156. to be resolved at run time.
  157. </p>
  158. <p>When implementing patterns for these built-in functions, the memory order
  159. parameter can be ignored as long as the pattern implements the most
  160. restrictive <code>__ATOMIC_SEQ_CST</code> memory order. Any of the other memory
  161. orders execute correctly with this memory order but they may not execute as
  162. efficiently as they could with a more appropriate implementation of the
  163. relaxed requirements.
  164. </p>
  165. <p>Note that the C++11 standard allows for the memory order parameter to be
  166. determined at run time rather than at compile time. These built-in
  167. functions map any run-time value to <code>__ATOMIC_SEQ_CST</code> rather
  168. than invoke a runtime library call or inline a switch statement. This is
  169. standard compliant, safe, and the simplest approach for now.
  170. </p>
  171. <p>The memory order parameter is a signed int, but only the lower 16 bits are
  172. reserved for the memory order. The remainder of the signed int is reserved
  173. for target use and should be 0. Use of the predefined atomic values
  174. ensures proper usage.
  175. </p>
  176. <dl>
  177. <dt><a name="index-_005f_005fatomic_005fload_005fn"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_load_n</strong> <em>(<var>type</var> *ptr, int memorder)</em></dt>
  178. <dd><p>This built-in function implements an atomic load operation. It returns the
  179. contents of <code>*<var>ptr</var></code>.
  180. </p>
  181. <p>The valid memory order variants are
  182. <code>__ATOMIC_RELAXED</code>, <code>__ATOMIC_SEQ_CST</code>, <code>__ATOMIC_ACQUIRE</code>,
  183. and <code>__ATOMIC_CONSUME</code>.
  184. </p>
  185. </dd></dl>
  186. <dl>
  187. <dt><a name="index-_005f_005fatomic_005fload"></a>Built-in Function: <em>void</em> <strong>__atomic_load</strong> <em>(<var>type</var> *ptr, <var>type</var> *ret, int memorder)</em></dt>
  188. <dd><p>This is the generic version of an atomic load. It returns the
  189. contents of <code>*<var>ptr</var></code> in <code>*<var>ret</var></code>.
  190. </p>
  191. </dd></dl>
  192. <dl>
  193. <dt><a name="index-_005f_005fatomic_005fstore_005fn"></a>Built-in Function: <em>void</em> <strong>__atomic_store_n</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  194. <dd><p>This built-in function implements an atomic store operation. It writes
  195. <code><var>val</var></code> into <code>*<var>ptr</var></code>.
  196. </p>
  197. <p>The valid memory order variants are
  198. <code>__ATOMIC_RELAXED</code>, <code>__ATOMIC_SEQ_CST</code>, and <code>__ATOMIC_RELEASE</code>.
  199. </p>
  200. </dd></dl>
  201. <dl>
  202. <dt><a name="index-_005f_005fatomic_005fstore"></a>Built-in Function: <em>void</em> <strong>__atomic_store</strong> <em>(<var>type</var> *ptr, <var>type</var> *val, int memorder)</em></dt>
  203. <dd><p>This is the generic version of an atomic store. It stores the value
  204. of <code>*<var>val</var></code> into <code>*<var>ptr</var></code>.
  205. </p>
  206. </dd></dl>
  207. <dl>
  208. <dt><a name="index-_005f_005fatomic_005fexchange_005fn"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_exchange_n</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  209. <dd><p>This built-in function implements an atomic exchange operation. It writes
  210. <var>val</var> into <code>*<var>ptr</var></code>, and returns the previous contents of
  211. <code>*<var>ptr</var></code>.
  212. </p>
  213. <p>The valid memory order variants are
  214. <code>__ATOMIC_RELAXED</code>, <code>__ATOMIC_SEQ_CST</code>, <code>__ATOMIC_ACQUIRE</code>,
  215. <code>__ATOMIC_RELEASE</code>, and <code>__ATOMIC_ACQ_REL</code>.
  216. </p>
  217. </dd></dl>
  218. <dl>
  219. <dt><a name="index-_005f_005fatomic_005fexchange"></a>Built-in Function: <em>void</em> <strong>__atomic_exchange</strong> <em>(<var>type</var> *ptr, <var>type</var> *val, <var>type</var> *ret, int memorder)</em></dt>
  220. <dd><p>This is the generic version of an atomic exchange. It stores the
  221. contents of <code>*<var>val</var></code> into <code>*<var>ptr</var></code>. The original value
  222. of <code>*<var>ptr</var></code> is copied into <code>*<var>ret</var></code>.
  223. </p>
  224. </dd></dl>
  225. <dl>
  226. <dt><a name="index-_005f_005fatomic_005fcompare_005fexchange_005fn"></a>Built-in Function: <em>bool</em> <strong>__atomic_compare_exchange_n</strong> <em>(<var>type</var> *ptr, <var>type</var> *expected, <var>type</var> desired, bool weak, int success_memorder, int failure_memorder)</em></dt>
  227. <dd><p>This built-in function implements an atomic compare and exchange operation.
  228. This compares the contents of <code>*<var>ptr</var></code> with the contents of
  229. <code>*<var>expected</var></code>. If equal, the operation is a <em>read-modify-write</em>
  230. operation that writes <var>desired</var> into <code>*<var>ptr</var></code>. If they are not
  231. equal, the operation is a <em>read</em> and the current contents of
  232. <code>*<var>ptr</var></code> are written into <code>*<var>expected</var></code>. <var>weak</var> is <code>true</code>
  233. for weak compare_exchange, which may fail spuriously, and <code>false</code> for
  234. the strong variation, which never fails spuriously. Many targets
  235. only offer the strong variation and ignore the parameter. When in doubt, use
  236. the strong variation.
  237. </p>
  238. <p>If <var>desired</var> is written into <code>*<var>ptr</var></code> then <code>true</code> is returned
  239. and memory is affected according to the
  240. memory order specified by <var>success_memorder</var>. There are no
  241. restrictions on what memory order can be used here.
  242. </p>
  243. <p>Otherwise, <code>false</code> is returned and memory is affected according
  244. to <var>failure_memorder</var>. This memory order cannot be
  245. <code>__ATOMIC_RELEASE</code> nor <code>__ATOMIC_ACQ_REL</code>. It also cannot be a
  246. stronger order than that specified by <var>success_memorder</var>.
  247. </p>
  248. </dd></dl>
  249. <dl>
  250. <dt><a name="index-_005f_005fatomic_005fcompare_005fexchange"></a>Built-in Function: <em>bool</em> <strong>__atomic_compare_exchange</strong> <em>(<var>type</var> *ptr, <var>type</var> *expected, <var>type</var> *desired, bool weak, int success_memorder, int failure_memorder)</em></dt>
  251. <dd><p>This built-in function implements the generic version of
  252. <code>__atomic_compare_exchange</code>. The function is virtually identical to
  253. <code>__atomic_compare_exchange_n</code>, except the desired value is also a
  254. pointer.
  255. </p>
  256. </dd></dl>
  257. <dl>
  258. <dt><a name="index-_005f_005fatomic_005fadd_005ffetch"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_add_fetch</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  259. <dt><a name="index-_005f_005fatomic_005fsub_005ffetch"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_sub_fetch</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  260. <dt><a name="index-_005f_005fatomic_005fand_005ffetch"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_and_fetch</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  261. <dt><a name="index-_005f_005fatomic_005fxor_005ffetch"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_xor_fetch</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  262. <dt><a name="index-_005f_005fatomic_005for_005ffetch"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_or_fetch</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  263. <dt><a name="index-_005f_005fatomic_005fnand_005ffetch"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_nand_fetch</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  264. <dd><p>These built-in functions perform the operation suggested by the name, and
  265. return the result of the operation. Operations on pointer arguments are
  266. performed as if the operands were of the <code>uintptr_t</code> type. That is,
  267. they are not scaled by the size of the type to which the pointer points.
  268. </p>
  269. <div class="smallexample">
  270. <pre class="smallexample">{ *ptr <var>op</var>= val; return *ptr; }
  271. { *ptr = ~(*ptr &amp; val); return *ptr; } // nand
  272. </pre></div>
  273. <p>The object pointed to by the first argument must be of integer or pointer
  274. type. It must not be a boolean type. All memory orders are valid.
  275. </p>
  276. </dd></dl>
  277. <dl>
  278. <dt><a name="index-_005f_005fatomic_005ffetch_005fadd"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_fetch_add</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  279. <dt><a name="index-_005f_005fatomic_005ffetch_005fsub"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_fetch_sub</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  280. <dt><a name="index-_005f_005fatomic_005ffetch_005fand"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_fetch_and</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  281. <dt><a name="index-_005f_005fatomic_005ffetch_005fxor"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_fetch_xor</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  282. <dt><a name="index-_005f_005fatomic_005ffetch_005for"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_fetch_or</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  283. <dt><a name="index-_005f_005fatomic_005ffetch_005fnand"></a>Built-in Function: <em><var>type</var></em> <strong>__atomic_fetch_nand</strong> <em>(<var>type</var> *ptr, <var>type</var> val, int memorder)</em></dt>
  284. <dd><p>These built-in functions perform the operation suggested by the name, and
  285. return the value that had previously been in <code>*<var>ptr</var></code>. Operations
  286. on pointer arguments are performed as if the operands were of
  287. the <code>uintptr_t</code> type. That is, they are not scaled by the size of
  288. the type to which the pointer points.
  289. </p>
  290. <div class="smallexample">
  291. <pre class="smallexample">{ tmp = *ptr; *ptr <var>op</var>= val; return tmp; }
  292. { tmp = *ptr; *ptr = ~(*ptr &amp; val); return tmp; } // nand
  293. </pre></div>
  294. <p>The same constraints on arguments apply as for the corresponding
  295. <code>__atomic_op_fetch</code> built-in functions. All memory orders are valid.
  296. </p>
  297. </dd></dl>
  298. <dl>
  299. <dt><a name="index-_005f_005fatomic_005ftest_005fand_005fset"></a>Built-in Function: <em>bool</em> <strong>__atomic_test_and_set</strong> <em>(void *ptr, int memorder)</em></dt>
  300. <dd>
  301. <p>This built-in function performs an atomic test-and-set operation on
  302. the byte at <code>*<var>ptr</var></code>. The byte is set to some implementation
  303. defined nonzero &ldquo;set&rdquo; value and the return value is <code>true</code> if and only
  304. if the previous contents were &ldquo;set&rdquo;.
  305. It should be only used for operands of type <code>bool</code> or <code>char</code>. For
  306. other types only part of the value may be set.
  307. </p>
  308. <p>All memory orders are valid.
  309. </p>
  310. </dd></dl>
  311. <dl>
  312. <dt><a name="index-_005f_005fatomic_005fclear"></a>Built-in Function: <em>void</em> <strong>__atomic_clear</strong> <em>(bool *ptr, int memorder)</em></dt>
  313. <dd>
  314. <p>This built-in function performs an atomic clear operation on
  315. <code>*<var>ptr</var></code>. After the operation, <code>*<var>ptr</var></code> contains 0.
  316. It should be only used for operands of type <code>bool</code> or <code>char</code> and
  317. in conjunction with <code>__atomic_test_and_set</code>.
  318. For other types it may only clear partially. If the type is not <code>bool</code>
  319. prefer using <code>__atomic_store</code>.
  320. </p>
  321. <p>The valid memory order variants are
  322. <code>__ATOMIC_RELAXED</code>, <code>__ATOMIC_SEQ_CST</code>, and
  323. <code>__ATOMIC_RELEASE</code>.
  324. </p>
  325. </dd></dl>
  326. <dl>
  327. <dt><a name="index-_005f_005fatomic_005fthread_005ffence"></a>Built-in Function: <em>void</em> <strong>__atomic_thread_fence</strong> <em>(int memorder)</em></dt>
  328. <dd>
  329. <p>This built-in function acts as a synchronization fence between threads
  330. based on the specified memory order.
  331. </p>
  332. <p>All memory orders are valid.
  333. </p>
  334. </dd></dl>
  335. <dl>
  336. <dt><a name="index-_005f_005fatomic_005fsignal_005ffence"></a>Built-in Function: <em>void</em> <strong>__atomic_signal_fence</strong> <em>(int memorder)</em></dt>
  337. <dd>
  338. <p>This built-in function acts as a synchronization fence between a thread
  339. and signal handlers based in the same thread.
  340. </p>
  341. <p>All memory orders are valid.
  342. </p>
  343. </dd></dl>
  344. <dl>
  345. <dt><a name="index-_005f_005fatomic_005falways_005flock_005ffree"></a>Built-in Function: <em>bool</em> <strong>__atomic_always_lock_free</strong> <em>(size_t size, void *ptr)</em></dt>
  346. <dd>
  347. <p>This built-in function returns <code>true</code> if objects of <var>size</var> bytes always
  348. generate lock-free atomic instructions for the target architecture.
  349. <var>size</var> must resolve to a compile-time constant and the result also
  350. resolves to a compile-time constant.
  351. </p>
  352. <p><var>ptr</var> is an optional pointer to the object that may be used to determine
  353. alignment. A value of 0 indicates typical alignment should be used. The
  354. compiler may also ignore this parameter.
  355. </p>
  356. <div class="smallexample">
  357. <pre class="smallexample">if (__atomic_always_lock_free (sizeof (long long), 0))
  358. </pre></div>
  359. </dd></dl>
  360. <dl>
  361. <dt><a name="index-_005f_005fatomic_005fis_005flock_005ffree"></a>Built-in Function: <em>bool</em> <strong>__atomic_is_lock_free</strong> <em>(size_t size, void *ptr)</em></dt>
  362. <dd>
  363. <p>This built-in function returns <code>true</code> if objects of <var>size</var> bytes always
  364. generate lock-free atomic instructions for the target architecture. If
  365. the built-in function is not known to be lock-free, a call is made to a
  366. runtime routine named <code>__atomic_is_lock_free</code>.
  367. </p>
  368. <p><var>ptr</var> is an optional pointer to the object that may be used to determine
  369. alignment. A value of 0 indicates typical alignment should be used. The
  370. compiler may also ignore this parameter.
  371. </p></dd></dl>
  372. <hr>
  373. <div class="header">
  374. <p>
  375. Next: <a href="Integer-Overflow-Builtins.html#Integer-Overflow-Builtins" accesskey="n" rel="next">Integer Overflow Builtins</a>, Previous: <a href="_005f_005fsync-Builtins.html#g_t_005f_005fsync-Builtins" accesskey="p" rel="prev">__sync Builtins</a>, Up: <a href="C-Extensions.html#C-Extensions" accesskey="u" rel="up">C Extensions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  376. </div>
  377. </body>
  378. </html>