_005f_005fatomic-Builtins.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>Using the GNU Compiler Collection (GCC): __atomic Builtins</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): __atomic Builtins">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): __atomic Builtins">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="g_t_005f_005fatomic-Builtins"></a>
  63. <div class="header">
  64. <p>
  65. 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>
  66. </div>
  67. <hr>
  68. <a name="Built_002din-Functions-for-Memory-Model-Aware-Atomic-Operations"></a>
  69. <h3 class="section">6.53 Built-in Functions for Memory Model Aware Atomic Operations</h3>
  70. <p>The following built-in functions approximately match the requirements
  71. for the C++11 memory model. They are all
  72. identified by being prefixed with &lsquo;<samp>__atomic</samp>&rsquo; and most are
  73. overloaded so that they work with multiple types.
  74. </p>
  75. <p>These functions are intended to replace the legacy &lsquo;<samp>__sync</samp>&rsquo;
  76. builtins. The main difference is that the memory order that is requested
  77. is a parameter to the functions. New code should always use the
  78. &lsquo;<samp>__atomic</samp>&rsquo; builtins rather than the &lsquo;<samp>__sync</samp>&rsquo; builtins.
  79. </p>
  80. <p>Note that the &lsquo;<samp>__atomic</samp>&rsquo; builtins assume that programs will
  81. conform to the C++11 memory model. In particular, they assume
  82. that programs are free of data races. See the C++11 standard for
  83. detailed requirements.
  84. </p>
  85. <p>The &lsquo;<samp>__atomic</samp>&rsquo; builtins can be used with any integral scalar or
  86. pointer type that is 1, 2, 4, or 8 bytes in length. 16-byte integral
  87. types are also allowed if &lsquo;<samp>__int128</samp>&rsquo; (see <a href="_005f_005fint128.html#g_t_005f_005fint128">__int128</a>) is
  88. supported by the architecture.
  89. </p>
  90. <p>The four non-arithmetic functions (load, store, exchange, and
  91. compare_exchange) all have a generic version as well. This generic
  92. version works on any data type. It uses the lock-free built-in function
  93. if the specific data type size makes that possible; otherwise, an
  94. external call is left to be resolved at run time. This external call is
  95. the same format with the addition of a &lsquo;<samp>size_t</samp>&rsquo; parameter inserted
  96. as the first parameter indicating the size of the object being pointed to.
  97. All objects must be the same size.
  98. </p>
  99. <p>There are 6 different memory orders that can be specified. These map
  100. to the C++11 memory orders with the same names, see the C++11 standard
  101. or the <a href="http://gcc.gnu.org/wiki/Atomic/GCCMM/AtomicSync">GCC wiki
  102. on atomic synchronization</a> for detailed definitions. Individual
  103. targets may also support additional memory orders for use on specific
  104. architectures. Refer to the target documentation for details of
  105. these.
  106. </p>
  107. <p>An atomic operation can both constrain code motion and
  108. be mapped to hardware instructions for synchronization between threads
  109. (e.g., a fence). To which extent this happens is controlled by the
  110. memory orders, which are listed here in approximately ascending order of
  111. strength. The description of each memory order is only meant to roughly
  112. illustrate the effects and is not a specification; see the C++11
  113. memory model for precise semantics.
  114. </p>
  115. <dl compact="compact">
  116. <dt><code>__ATOMIC_RELAXED</code></dt>
  117. <dd><p>Implies no inter-thread ordering constraints.
  118. </p></dd>
  119. <dt><code>__ATOMIC_CONSUME</code></dt>
  120. <dd><p>This is currently implemented using the stronger <code>__ATOMIC_ACQUIRE</code>
  121. memory order because of a deficiency in C++11&rsquo;s semantics for
  122. <code>memory_order_consume</code>.
  123. </p></dd>
  124. <dt><code>__ATOMIC_ACQUIRE</code></dt>
  125. <dd><p>Creates an inter-thread happens-before constraint from the release (or
  126. stronger) semantic store to this acquire load. Can prevent hoisting
  127. of code to before the operation.
  128. </p></dd>
  129. <dt><code>__ATOMIC_RELEASE</code></dt>
  130. <dd><p>Creates an inter-thread happens-before constraint to acquire (or stronger)
  131. semantic loads that read from this release store. Can prevent sinking
  132. of code to after the operation.
  133. </p></dd>
  134. <dt><code>__ATOMIC_ACQ_REL</code></dt>
  135. <dd><p>Combines the effects of both <code>__ATOMIC_ACQUIRE</code> and
  136. <code>__ATOMIC_RELEASE</code>.
  137. </p></dd>
  138. <dt><code>__ATOMIC_SEQ_CST</code></dt>
  139. <dd><p>Enforces total ordering with all other <code>__ATOMIC_SEQ_CST</code> operations.
  140. </p></dd>
  141. </dl>
  142. <p>Note that in the C++11 memory model, <em>fences</em> (e.g.,
  143. &lsquo;<samp>__atomic_thread_fence</samp>&rsquo;) take effect in combination with other
  144. atomic operations on specific memory locations (e.g., atomic loads);
  145. operations on specific memory locations do not necessarily affect other
  146. operations in the same way.
  147. </p>
  148. <p>Target architectures are encouraged to provide their own patterns for
  149. each of the atomic built-in functions. If no target is provided, the original
  150. non-memory model set of &lsquo;<samp>__sync</samp>&rsquo; atomic built-in functions are
  151. used, along with any required synchronization fences surrounding it in
  152. order to achieve the proper behavior. Execution in this case is subject
  153. to the same restrictions as those built-in functions.
  154. </p>
  155. <p>If there is no pattern or mechanism to provide a lock-free instruction
  156. sequence, a call is made to an external routine with the same parameters
  157. to be resolved at run time.
  158. </p>
  159. <p>When implementing patterns for these built-in functions, the memory order
  160. parameter can be ignored as long as the pattern implements the most
  161. restrictive <code>__ATOMIC_SEQ_CST</code> memory order. Any of the other memory
  162. orders execute correctly with this memory order but they may not execute as
  163. efficiently as they could with a more appropriate implementation of the
  164. relaxed requirements.
  165. </p>
  166. <p>Note that the C++11 standard allows for the memory order parameter to be
  167. determined at run time rather than at compile time. These built-in
  168. functions map any run-time value to <code>__ATOMIC_SEQ_CST</code> rather
  169. than invoke a runtime library call or inline a switch statement. This is
  170. standard compliant, safe, and the simplest approach for now.
  171. </p>
  172. <p>The memory order parameter is a signed int, but only the lower 16 bits are
  173. reserved for the memory order. The remainder of the signed int is reserved
  174. for target use and should be 0. Use of the predefined atomic values
  175. ensures proper usage.
  176. </p>
  177. <dl>
  178. <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>
  179. <dd><p>This built-in function implements an atomic load operation. It returns the
  180. contents of <code>*<var>ptr</var></code>.
  181. </p>
  182. <p>The valid memory order variants are
  183. <code>__ATOMIC_RELAXED</code>, <code>__ATOMIC_SEQ_CST</code>, <code>__ATOMIC_ACQUIRE</code>,
  184. and <code>__ATOMIC_CONSUME</code>.
  185. </p>
  186. </dd></dl>
  187. <dl>
  188. <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>
  189. <dd><p>This is the generic version of an atomic load. It returns the
  190. contents of <code>*<var>ptr</var></code> in <code>*<var>ret</var></code>.
  191. </p>
  192. </dd></dl>
  193. <dl>
  194. <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>
  195. <dd><p>This built-in function implements an atomic store operation. It writes
  196. <code><var>val</var></code> into <code>*<var>ptr</var></code>.
  197. </p>
  198. <p>The valid memory order variants are
  199. <code>__ATOMIC_RELAXED</code>, <code>__ATOMIC_SEQ_CST</code>, and <code>__ATOMIC_RELEASE</code>.
  200. </p>
  201. </dd></dl>
  202. <dl>
  203. <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>
  204. <dd><p>This is the generic version of an atomic store. It stores the value
  205. of <code>*<var>val</var></code> into <code>*<var>ptr</var></code>.
  206. </p>
  207. </dd></dl>
  208. <dl>
  209. <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>
  210. <dd><p>This built-in function implements an atomic exchange operation. It writes
  211. <var>val</var> into <code>*<var>ptr</var></code>, and returns the previous contents of
  212. <code>*<var>ptr</var></code>.
  213. </p>
  214. <p>The valid memory order variants are
  215. <code>__ATOMIC_RELAXED</code>, <code>__ATOMIC_SEQ_CST</code>, <code>__ATOMIC_ACQUIRE</code>,
  216. <code>__ATOMIC_RELEASE</code>, and <code>__ATOMIC_ACQ_REL</code>.
  217. </p>
  218. </dd></dl>
  219. <dl>
  220. <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>
  221. <dd><p>This is the generic version of an atomic exchange. It stores the
  222. contents of <code>*<var>val</var></code> into <code>*<var>ptr</var></code>. The original value
  223. of <code>*<var>ptr</var></code> is copied into <code>*<var>ret</var></code>.
  224. </p>
  225. </dd></dl>
  226. <dl>
  227. <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>
  228. <dd><p>This built-in function implements an atomic compare and exchange operation.
  229. This compares the contents of <code>*<var>ptr</var></code> with the contents of
  230. <code>*<var>expected</var></code>. If equal, the operation is a <em>read-modify-write</em>
  231. operation that writes <var>desired</var> into <code>*<var>ptr</var></code>. If they are not
  232. equal, the operation is a <em>read</em> and the current contents of
  233. <code>*<var>ptr</var></code> are written into <code>*<var>expected</var></code>. <var>weak</var> is true
  234. for weak compare_exchange, which may fail spuriously, and false for
  235. the strong variation, which never fails spuriously. Many targets
  236. only offer the strong variation and ignore the parameter. When in doubt, use
  237. the strong variation.
  238. </p>
  239. <p>If <var>desired</var> is written into <code>*<var>ptr</var></code> then true is returned
  240. and memory is affected according to the
  241. memory order specified by <var>success_memorder</var>. There are no
  242. restrictions on what memory order can be used here.
  243. </p>
  244. <p>Otherwise, false is returned and memory is affected according
  245. to <var>failure_memorder</var>. This memory order cannot be
  246. <code>__ATOMIC_RELEASE</code> nor <code>__ATOMIC_ACQ_REL</code>. It also cannot be a
  247. stronger order than that specified by <var>success_memorder</var>.
  248. </p>
  249. </dd></dl>
  250. <dl>
  251. <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>
  252. <dd><p>This built-in function implements the generic version of
  253. <code>__atomic_compare_exchange</code>. The function is virtually identical to
  254. <code>__atomic_compare_exchange_n</code>, except the desired value is also a
  255. pointer.
  256. </p>
  257. </dd></dl>
  258. <dl>
  259. <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>
  260. <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>
  261. <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>
  262. <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>
  263. <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>
  264. <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>
  265. <dd><p>These built-in functions perform the operation suggested by the name, and
  266. return the result of the operation. Operations on pointer arguments are
  267. performed as if the operands were of the <code>uintptr_t</code> type. That is,
  268. they are not scaled by the size of the type to which the pointer points.
  269. </p>
  270. <div class="smallexample">
  271. <pre class="smallexample">{ *ptr <var>op</var>= val; return *ptr; }
  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. </pre></div>
  293. <p>The same constraints on arguments apply as for the corresponding
  294. <code>__atomic_op_fetch</code> built-in functions. All memory orders are valid.
  295. </p>
  296. </dd></dl>
  297. <dl>
  298. <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>
  299. <dd>
  300. <p>This built-in function performs an atomic test-and-set operation on
  301. the byte at <code>*<var>ptr</var></code>. The byte is set to some implementation
  302. defined nonzero &ldquo;set&rdquo; value and the return value is <code>true</code> if and only
  303. if the previous contents were &ldquo;set&rdquo;.
  304. It should be only used for operands of type <code>bool</code> or <code>char</code>. For
  305. other types only part of the value may be set.
  306. </p>
  307. <p>All memory orders are valid.
  308. </p>
  309. </dd></dl>
  310. <dl>
  311. <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>
  312. <dd>
  313. <p>This built-in function performs an atomic clear operation on
  314. <code>*<var>ptr</var></code>. After the operation, <code>*<var>ptr</var></code> contains 0.
  315. It should be only used for operands of type <code>bool</code> or <code>char</code> and
  316. in conjunction with <code>__atomic_test_and_set</code>.
  317. For other types it may only clear partially. If the type is not <code>bool</code>
  318. prefer using <code>__atomic_store</code>.
  319. </p>
  320. <p>The valid memory order variants are
  321. <code>__ATOMIC_RELAXED</code>, <code>__ATOMIC_SEQ_CST</code>, and
  322. <code>__ATOMIC_RELEASE</code>.
  323. </p>
  324. </dd></dl>
  325. <dl>
  326. <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>
  327. <dd>
  328. <p>This built-in function acts as a synchronization fence between threads
  329. based on the specified memory order.
  330. </p>
  331. <p>All memory orders are valid.
  332. </p>
  333. </dd></dl>
  334. <dl>
  335. <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>
  336. <dd>
  337. <p>This built-in function acts as a synchronization fence between a thread
  338. and signal handlers based in the same thread.
  339. </p>
  340. <p>All memory orders are valid.
  341. </p>
  342. </dd></dl>
  343. <dl>
  344. <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>
  345. <dd>
  346. <p>This built-in function returns true if objects of <var>size</var> bytes always
  347. generate lock-free atomic instructions for the target architecture.
  348. <var>size</var> must resolve to a compile-time constant and the result also
  349. resolves to a compile-time constant.
  350. </p>
  351. <p><var>ptr</var> is an optional pointer to the object that may be used to determine
  352. alignment. A value of 0 indicates typical alignment should be used. The
  353. compiler may also ignore this parameter.
  354. </p>
  355. <div class="smallexample">
  356. <pre class="smallexample">if (__atomic_always_lock_free (sizeof (long long), 0))
  357. </pre></div>
  358. </dd></dl>
  359. <dl>
  360. <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>
  361. <dd>
  362. <p>This built-in function returns true if objects of <var>size</var> bytes always
  363. generate lock-free atomic instructions for the target architecture. If
  364. the built-in function is not known to be lock-free, a call is made to a
  365. runtime routine named <code>__atomic_is_lock_free</code>.
  366. </p>
  367. <p><var>ptr</var> is an optional pointer to the object that may be used to determine
  368. alignment. A value of 0 indicates typical alignment should be used. The
  369. compiler may also ignore this parameter.
  370. </p></dd></dl>
  371. <hr>
  372. <div class="header">
  373. <p>
  374. 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>
  375. </div>
  376. </body>
  377. </html>