2 * Copyright (c) 2004-2016 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef _OSATOMIC_DEPRECATED_H_
25 #define _OSATOMIC_DEPRECATED_H_
28 * These are deprecated legacy interfaces for atomic operations.
29 * The C11 interfaces in <stdatomic.h> resp. C++11 interfaces in <atomic>
30 * should be used instead.
32 * Define OSATOMIC_USE_INLINED=1 to get inline implementations of these
33 * interfaces in terms of the <stdatomic.h> resp. <atomic> primitives.
34 * This is intended as a transition convenience, direct use of those primitives
38 #if !(defined(OSATOMIC_USE_INLINED) && OSATOMIC_USE_INLINED)
40 #include <sys/cdefs.h>
44 #include <Availability.h>
46 #ifndef OSATOMIC_DEPRECATED
47 #define OSATOMIC_DEPRECATED 1
49 #define OSATOMIC_BARRIER_DEPRECATED_MSG(_r) \
50 "Use " #_r "() from <stdatomic.h> instead"
51 #define OSATOMIC_DEPRECATED_MSG(_r) \
52 "Use " #_r "_explicit(memory_order_relaxed) from <stdatomic.h> instead"
54 #define OSATOMIC_BARRIER_DEPRECATED_MSG(_r) \
55 "Use std::" #_r "() from <atomic> instead"
56 #define OSATOMIC_DEPRECATED_MSG(_r) \
57 "Use std::" #_r "_explicit(std::memory_order_relaxed) from <atomic> instead"
59 #define OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(_r) \
60 __OS_AVAILABILITY_MSG(macosx, deprecated=10.12, OSATOMIC_BARRIER_DEPRECATED_MSG(_r)) \
61 __OS_AVAILABILITY_MSG(ios, deprecated=10.0, OSATOMIC_BARRIER_DEPRECATED_MSG(_r)) \
62 __OS_AVAILABILITY_MSG(tvos, deprecated=10.0, OSATOMIC_BARRIER_DEPRECATED_MSG(_r)) \
63 __OS_AVAILABILITY_MSG(watchos, deprecated=3.0, OSATOMIC_BARRIER_DEPRECATED_MSG(_r))
64 #define OSATOMIC_DEPRECATED_REPLACE_WITH(_r) \
65 __OS_AVAILABILITY_MSG(macosx, deprecated=10.12, OSATOMIC_DEPRECATED_MSG(_r)) \
66 __OS_AVAILABILITY_MSG(ios, deprecated=10.0, OSATOMIC_DEPRECATED_MSG(_r)) \
67 __OS_AVAILABILITY_MSG(tvos, deprecated=10.0, OSATOMIC_DEPRECATED_MSG(_r)) \
68 __OS_AVAILABILITY_MSG(watchos, deprecated=3.0, OSATOMIC_DEPRECATED_MSG(_r))
70 #undef OSATOMIC_DEPRECATED
71 #define OSATOMIC_DEPRECATED 0
72 #define OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(_r)
73 #define OSATOMIC_DEPRECATED_REPLACE_WITH(_r)
77 * WARNING: all addresses passed to these functions must be "naturally aligned",
78 * i.e. <code>int32_t</code> pointers must be 32-bit aligned (low 2 bits of
79 * address are zeroes), and <code>int64_t</code> pointers must be 64-bit
80 * aligned (low 3 bits of address are zeroes.).
81 * Note that this is not the default alignment of the <code>int64_t</code> type
82 * in the iOS ARMv7 ABI, see
83 * {@link //apple_ref/doc/uid/TP40009021-SW8 iPhoneOSABIReference}
85 * Note that some versions of the atomic functions incorporate memory barriers
86 * and some do not. Barriers strictly order memory access on weakly-ordered
87 * architectures such as ARM. All loads and stores that appear (in sequential
88 * program order) before the barrier are guaranteed to complete before any
89 * load or store that appears after the barrier.
91 * The barrier operation is typically a no-op on uniprocessor systems and
92 * fully enabled on multiprocessor systems. On some platforms, such as ARM,
93 * the barrier can be quite expensive.
95 * Most code should use the barrier functions to ensure that memory shared
96 * between threads is properly synchronized. For example, if you want to
97 * initialize a shared data structure and then atomically increment a variable
98 * to indicate that the initialization is complete, you must use
99 * {@link OSAtomicIncrement32Barrier} to ensure that the stores to your data
100 * structure complete before the atomic increment.
102 * Likewise, the consumer of that data structure must use
103 * {@link OSAtomicDecrement32Barrier},
104 * in order to ensure that their loads of the structure are not executed before
105 * the atomic decrement. On the other hand, if you are simply incrementing a
106 * global counter, then it is safe and potentially faster to use
107 * {@link OSAtomicIncrement32}.
109 * If you are unsure which version to use, prefer the barrier variants as they
112 * For the kernel-space version of this header, see
113 * {@link //apple_ref/doc/header/OSAtomic.h OSAtomic.h (Kernel Framework)}
115 * @apiuid //apple_ref/doc/header/user_space_OSAtomic.h
120 /*! @typedef OSAtomic_int64_aligned64_t
121 * 64-bit aligned <code>int64_t</code> type.
122 * Use for variables whose addresses are passed to OSAtomic*64() functions to
123 * get the compiler to generate the required alignment.
126 #if __has_attribute(aligned)
127 typedef int64_t __attribute__((__aligned__((sizeof(int64_t)))))
128 OSAtomic_int64_aligned64_t
;
130 typedef int64_t OSAtomic_int64_aligned64_t
;
133 /*! @group Arithmetic functions
134 All functions in this group return the new value.
137 /*! @abstract Atomically adds two 32-bit values.
139 This function adds the value given by <code>__theAmount</code> to the
140 value in the memory location referenced by <code>__theValue</code>,
141 storing the result back to that memory location atomically.
142 @result Returns the new value.
144 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
145 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
146 int32_t OSAtomicAdd32( int32_t __theAmount
, volatile int32_t *__theValue
);
149 /*! @abstract Atomically adds two 32-bit values.
151 This function adds the value given by <code>__theAmount</code> to the
152 value in the memory location referenced by <code>__theValue</code>,
153 storing the result back to that memory location atomically.
155 This function is equivalent to {@link OSAtomicAdd32}
156 except that it also introduces a barrier.
157 @result Returns the new value.
159 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
160 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
161 int32_t OSAtomicAdd32Barrier( int32_t __theAmount
, volatile int32_t *__theValue
);
164 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10 || __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_7_1
166 /*! @abstract Atomically increments a 32-bit value.
167 @result Returns the new value.
169 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
170 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
171 int32_t OSAtomicIncrement32( volatile int32_t *__theValue
);
174 /*! @abstract Atomically increments a 32-bit value with a barrier.
176 This function is equivalent to {@link OSAtomicIncrement32}
177 except that it also introduces a barrier.
178 @result Returns the new value.
180 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
181 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
182 int32_t OSAtomicIncrement32Barrier( volatile int32_t *__theValue
);
185 /*! @abstract Atomically decrements a 32-bit value.
186 @result Returns the new value.
188 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_sub
)
189 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
190 int32_t OSAtomicDecrement32( volatile int32_t *__theValue
);
193 /*! @abstract Atomically decrements a 32-bit value with a barrier.
195 This function is equivalent to {@link OSAtomicDecrement32}
196 except that it also introduces a barrier.
197 @result Returns the new value.
199 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_sub
)
200 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
201 int32_t OSAtomicDecrement32Barrier( volatile int32_t *__theValue
);
205 int32_t OSAtomicIncrement32( volatile int32_t *__theValue
)
206 { return OSAtomicAdd32( 1, __theValue
); }
209 int32_t OSAtomicIncrement32Barrier( volatile int32_t *__theValue
)
210 { return OSAtomicAdd32Barrier( 1, __theValue
); }
213 int32_t OSAtomicDecrement32( volatile int32_t *__theValue
)
214 { return OSAtomicAdd32( -1, __theValue
); }
217 int32_t OSAtomicDecrement32Barrier( volatile int32_t *__theValue
)
218 { return OSAtomicAdd32Barrier( -1, __theValue
); }
222 /*! @abstract Atomically adds two 64-bit values.
224 This function adds the value given by <code>__theAmount</code> to the
225 value in the memory location referenced by <code>__theValue</code>,
226 storing the result back to that memory location atomically.
227 @result Returns the new value.
229 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
230 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
231 int64_t OSAtomicAdd64( int64_t __theAmount
,
232 volatile OSAtomic_int64_aligned64_t
*__theValue
);
235 /*! @abstract Atomically adds two 64-bit values with a barrier.
237 This function adds the value given by <code>__theAmount</code> to the
238 value in the memory location referenced by <code>__theValue</code>,
239 storing the result back to that memory location atomically.
241 This function is equivalent to {@link OSAtomicAdd64}
242 except that it also introduces a barrier.
243 @result Returns the new value.
245 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
246 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_3_2
)
247 int64_t OSAtomicAdd64Barrier( int64_t __theAmount
,
248 volatile OSAtomic_int64_aligned64_t
*__theValue
);
251 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10 || __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_7_1
253 /*! @abstract Atomically increments a 64-bit value.
254 @result Returns the new value.
256 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
257 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
258 int64_t OSAtomicIncrement64( volatile OSAtomic_int64_aligned64_t
*__theValue
);
261 /*! @abstract Atomically increments a 64-bit value with a barrier.
263 This function is equivalent to {@link OSAtomicIncrement64}
264 except that it also introduces a barrier.
265 @result Returns the new value.
267 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
268 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
269 int64_t OSAtomicIncrement64Barrier( volatile OSAtomic_int64_aligned64_t
*__theValue
);
272 /*! @abstract Atomically decrements a 64-bit value.
273 @result Returns the new value.
275 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_sub
)
276 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
277 int64_t OSAtomicDecrement64( volatile OSAtomic_int64_aligned64_t
*__theValue
);
280 /*! @abstract Atomically decrements a 64-bit value with a barrier.
282 This function is equivalent to {@link OSAtomicDecrement64}
283 except that it also introduces a barrier.
284 @result Returns the new value.
286 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_sub
)
287 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
288 int64_t OSAtomicDecrement64Barrier( volatile OSAtomic_int64_aligned64_t
*__theValue
);
292 int64_t OSAtomicIncrement64( volatile OSAtomic_int64_aligned64_t
*__theValue
)
293 { return OSAtomicAdd64( 1, __theValue
); }
296 int64_t OSAtomicIncrement64Barrier( volatile OSAtomic_int64_aligned64_t
*__theValue
)
297 { return OSAtomicAdd64Barrier( 1, __theValue
); }
300 int64_t OSAtomicDecrement64( volatile OSAtomic_int64_aligned64_t
*__theValue
)
301 { return OSAtomicAdd64( -1, __theValue
); }
304 int64_t OSAtomicDecrement64Barrier( volatile OSAtomic_int64_aligned64_t
*__theValue
)
305 { return OSAtomicAdd64Barrier( -1, __theValue
); }
309 /*! @group Boolean functions (AND, OR, XOR)
311 * @discussion Functions in this group come in four variants for each operation:
312 * with and without barriers, and functions that return the original value or
313 * the result value of the operation.
315 * The "Orig" versions return the original value, (before the operation); the non-Orig
316 * versions return the value after the operation. All are layered on top of
317 * {@link OSAtomicCompareAndSwap32} and similar.
320 /*! @abstract Atomic bitwise OR of two 32-bit values.
322 This function performs the bitwise OR of the value given by <code>__theMask</code>
323 with the value in the memory location referenced by <code>__theValue</code>,
324 storing the result back to that memory location atomically.
325 @result Returns the new value.
327 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
328 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
329 int32_t OSAtomicOr32( uint32_t __theMask
, volatile uint32_t *__theValue
);
332 /*! @abstract Atomic bitwise OR of two 32-bit values with barrier.
334 This function performs the bitwise OR of the value given by <code>__theMask</code>
335 with the value in the memory location referenced by <code>__theValue</code>,
336 storing the result back to that memory location atomically.
338 This function is equivalent to {@link OSAtomicOr32}
339 except that it also introduces a barrier.
340 @result Returns the new value.
342 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
343 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
344 int32_t OSAtomicOr32Barrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
347 /*! @abstract Atomic bitwise OR of two 32-bit values returning original.
349 This function performs the bitwise OR of the value given by <code>__theMask</code>
350 with the value in the memory location referenced by <code>__theValue</code>,
351 storing the result back to that memory location atomically.
352 @result Returns the original value referenced by <code>__theValue</code>.
354 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
355 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
356 int32_t OSAtomicOr32Orig( uint32_t __theMask
, volatile uint32_t *__theValue
);
359 /*! @abstract Atomic bitwise OR of two 32-bit values returning original with barrier.
361 This function performs the bitwise OR of the value given by <code>__theMask</code>
362 with the value in the memory location referenced by <code>__theValue</code>,
363 storing the result back to that memory location atomically.
365 This function is equivalent to {@link OSAtomicOr32Orig}
366 except that it also introduces a barrier.
367 @result Returns the original value referenced by <code>__theValue</code>.
369 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
370 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
371 int32_t OSAtomicOr32OrigBarrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
376 /*! @abstract Atomic bitwise AND of two 32-bit values.
378 This function performs the bitwise AND of the value given by <code>__theMask</code>
379 with the value in the memory location referenced by <code>__theValue</code>,
380 storing the result back to that memory location atomically.
381 @result Returns the new value.
383 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
384 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
385 int32_t OSAtomicAnd32( uint32_t __theMask
, volatile uint32_t *__theValue
);
388 /*! @abstract Atomic bitwise AND of two 32-bit values with barrier.
390 This function performs the bitwise AND of the value given by <code>__theMask</code>
391 with the value in the memory location referenced by <code>__theValue</code>,
392 storing the result back to that memory location atomically.
394 This function is equivalent to {@link OSAtomicAnd32}
395 except that it also introduces a barrier.
396 @result Returns the new value.
398 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
399 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
400 int32_t OSAtomicAnd32Barrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
403 /*! @abstract Atomic bitwise AND of two 32-bit values returning original.
405 This function performs the bitwise AND of the value given by <code>__theMask</code>
406 with the value in the memory location referenced by <code>__theValue</code>,
407 storing the result back to that memory location atomically.
408 @result Returns the original value referenced by <code>__theValue</code>.
410 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
411 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
412 int32_t OSAtomicAnd32Orig( uint32_t __theMask
, volatile uint32_t *__theValue
);
415 /*! @abstract Atomic bitwise AND of two 32-bit values returning original with barrier.
417 This function performs the bitwise AND of the value given by <code>__theMask</code>
418 with the value in the memory location referenced by <code>__theValue</code>,
419 storing the result back to that memory location atomically.
421 This function is equivalent to {@link OSAtomicAnd32Orig}
422 except that it also introduces a barrier.
423 @result Returns the original value referenced by <code>__theValue</code>.
425 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
426 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
427 int32_t OSAtomicAnd32OrigBarrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
432 /*! @abstract Atomic bitwise XOR of two 32-bit values.
434 This function performs the bitwise XOR of the value given by <code>__theMask</code>
435 with the value in the memory location referenced by <code>__theValue</code>,
436 storing the result back to that memory location atomically.
437 @result Returns the new value.
439 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_xor
)
440 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
441 int32_t OSAtomicXor32( uint32_t __theMask
, volatile uint32_t *__theValue
);
444 /*! @abstract Atomic bitwise XOR of two 32-bit values with barrier.
446 This function performs the bitwise XOR of the value given by <code>__theMask</code>
447 with the value in the memory location referenced by <code>__theValue</code>,
448 storing the result back to that memory location atomically.
450 This function is equivalent to {@link OSAtomicXor32}
451 except that it also introduces a barrier.
452 @result Returns the new value.
454 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_xor
)
455 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
456 int32_t OSAtomicXor32Barrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
459 /*! @abstract Atomic bitwise XOR of two 32-bit values returning original.
461 This function performs the bitwise XOR of the value given by <code>__theMask</code>
462 with the value in the memory location referenced by <code>__theValue</code>,
463 storing the result back to that memory location atomically.
464 @result Returns the original value referenced by <code>__theValue</code>.
466 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_xor
)
467 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
468 int32_t OSAtomicXor32Orig( uint32_t __theMask
, volatile uint32_t *__theValue
);
471 /*! @abstract Atomic bitwise XOR of two 32-bit values returning original with barrier.
473 This function performs the bitwise XOR of the value given by <code>__theMask</code>
474 with the value in the memory location referenced by <code>__theValue</code>,
475 storing the result back to that memory location atomically.
477 This function is equivalent to {@link OSAtomicXor32Orig}
478 except that it also introduces a barrier.
479 @result Returns the original value referenced by <code>__theValue</code>.
481 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_xor
)
482 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
483 int32_t OSAtomicXor32OrigBarrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
486 /*! @group Compare and swap
487 * Functions in this group return true if the swap occured. There are several versions,
488 * depending on data type and on whether or not a barrier is used.
492 /*! @abstract Compare and swap for 32-bit values.
494 This function compares the value in <code>__oldValue</code> to the value
495 in the memory location referenced by <code>__theValue</code>. If the values
496 match, this function stores the value from <code>__newValue</code> into
497 that memory location atomically.
498 @result Returns TRUE on a match, FALSE otherwise.
500 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
501 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
502 bool OSAtomicCompareAndSwap32( int32_t __oldValue
, int32_t __newValue
, volatile int32_t *__theValue
);
505 /*! @abstract Compare and swap for 32-bit values with barrier.
507 This function compares the value in <code>__oldValue</code> to the value
508 in the memory location referenced by <code>__theValue</code>. If the values
509 match, this function stores the value from <code>__newValue</code> into
510 that memory location atomically.
512 This function is equivalent to {@link OSAtomicCompareAndSwap32}
513 except that it also introduces a barrier.
514 @result Returns TRUE on a match, FALSE otherwise.
516 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
517 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
518 bool OSAtomicCompareAndSwap32Barrier( int32_t __oldValue
, int32_t __newValue
, volatile int32_t *__theValue
);
521 /*! @abstract Compare and swap pointers.
523 This function compares the pointer stored in <code>__oldValue</code> to the pointer
524 in the memory location referenced by <code>__theValue</code>. If the pointers
525 match, this function stores the pointer from <code>__newValue</code> into
526 that memory location atomically.
527 @result Returns TRUE on a match, FALSE otherwise.
529 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
530 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
531 bool OSAtomicCompareAndSwapPtr( void *__oldValue
, void *__newValue
, void * volatile *__theValue
);
534 /*! @abstract Compare and swap pointers with barrier.
536 This function compares the pointer stored in <code>__oldValue</code> to the pointer
537 in the memory location referenced by <code>__theValue</code>. If the pointers
538 match, this function stores the pointer from <code>__newValue</code> into
539 that memory location atomically.
541 This function is equivalent to {@link OSAtomicCompareAndSwapPtr}
542 except that it also introduces a barrier.
543 @result Returns TRUE on a match, FALSE otherwise.
545 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
546 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
547 bool OSAtomicCompareAndSwapPtrBarrier( void *__oldValue
, void *__newValue
, void * volatile *__theValue
);
550 /*! @abstract Compare and swap for <code>int</code> values.
552 This function compares the value in <code>__oldValue</code> to the value
553 in the memory location referenced by <code>__theValue</code>. If the values
554 match, this function stores the value from <code>__newValue</code> into
555 that memory location atomically.
557 This function is equivalent to {@link OSAtomicCompareAndSwap32}.
558 @result Returns TRUE on a match, FALSE otherwise.
560 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
561 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
562 bool OSAtomicCompareAndSwapInt( int __oldValue
, int __newValue
, volatile int *__theValue
);
565 /*! @abstract Compare and swap for <code>int</code> values.
567 This function compares the value in <code>__oldValue</code> to the value
568 in the memory location referenced by <code>__theValue</code>. If the values
569 match, this function stores the value from <code>__newValue</code> into
570 that memory location atomically.
572 This function is equivalent to {@link OSAtomicCompareAndSwapInt}
573 except that it also introduces a barrier.
575 This function is equivalent to {@link OSAtomicCompareAndSwap32Barrier}.
576 @result Returns TRUE on a match, FALSE otherwise.
578 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
579 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
580 bool OSAtomicCompareAndSwapIntBarrier( int __oldValue
, int __newValue
, volatile int *__theValue
);
583 /*! @abstract Compare and swap for <code>long</code> values.
585 This function compares the value in <code>__oldValue</code> to the value
586 in the memory location referenced by <code>__theValue</code>. If the values
587 match, this function stores the value from <code>__newValue</code> into
588 that memory location atomically.
590 This function is equivalent to {@link OSAtomicCompareAndSwap32} on 32-bit architectures,
591 or {@link OSAtomicCompareAndSwap64} on 64-bit architectures.
592 @result Returns TRUE on a match, FALSE otherwise.
594 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
595 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
596 bool OSAtomicCompareAndSwapLong( long __oldValue
, long __newValue
, volatile long *__theValue
);
599 /*! @abstract Compare and swap for <code>long</code> values.
601 This function compares the value in <code>__oldValue</code> to the value
602 in the memory location referenced by <code>__theValue</code>. If the values
603 match, this function stores the value from <code>__newValue</code> into
604 that memory location atomically.
606 This function is equivalent to {@link OSAtomicCompareAndSwapLong}
607 except that it also introduces a barrier.
609 This function is equivalent to {@link OSAtomicCompareAndSwap32} on 32-bit architectures,
610 or {@link OSAtomicCompareAndSwap64} on 64-bit architectures.
611 @result Returns TRUE on a match, FALSE otherwise.
613 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
614 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
615 bool OSAtomicCompareAndSwapLongBarrier( long __oldValue
, long __newValue
, volatile long *__theValue
);
618 /*! @abstract Compare and swap for <code>uint64_t</code> values.
620 This function compares the value in <code>__oldValue</code> to the value
621 in the memory location referenced by <code>__theValue</code>. If the values
622 match, this function stores the value from <code>__newValue</code> into
623 that memory location atomically.
624 @result Returns TRUE on a match, FALSE otherwise.
626 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
627 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
628 bool OSAtomicCompareAndSwap64( int64_t __oldValue
, int64_t __newValue
,
629 volatile OSAtomic_int64_aligned64_t
*__theValue
);
632 /*! @abstract Compare and swap for <code>uint64_t</code> values.
634 This function compares the value in <code>__oldValue</code> to the value
635 in the memory location referenced by <code>__theValue</code>. If the values
636 match, this function stores the value from <code>__newValue</code> into
637 that memory location atomically.
639 This function is equivalent to {@link OSAtomicCompareAndSwap64}
640 except that it also introduces a barrier.
641 @result Returns TRUE on a match, FALSE otherwise.
643 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
644 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_3_2
)
645 bool OSAtomicCompareAndSwap64Barrier( int64_t __oldValue
, int64_t __newValue
,
646 volatile OSAtomic_int64_aligned64_t
*__theValue
);
650 * They return the original value of the bit, and operate on bit (0x80>>(n&7))
651 * in byte ((char*)theAddress + (n>>3)).
653 /*! @abstract Atomic test and set
655 This function tests a bit in the value referenced by
656 <code>__theAddress</code> and if it is not set, sets it.
658 The bit is chosen by the value of <code>__n</code> such that the
659 operation will be performed on bit <code>(0x80 >> (__n & 7))</code>
660 of byte <code>((char *)__theAddress + (n >> 3))</code>.
662 For example, if <code>__theAddress</code> points to a 64-bit value,
663 to compare the value of the most significant bit, you would specify
664 <code>56</code> for <code>__n</code>.
666 Returns the original value of the bit being tested.
668 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
669 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
670 bool OSAtomicTestAndSet( uint32_t __n
, volatile void *__theAddress
);
673 /*! @abstract Atomic test and set with barrier
675 This function tests a bit in the value referenced by <code>__theAddress</code>
676 and if it is not set, sets it.
678 The bit is chosen by the value of <code>__n</code> such that the
679 operation will be performed on bit <code>(0x80 >> (__n & 7))</code>
680 of byte <code>((char *)__theAddress + (n >> 3))</code>.
682 For example, if <code>__theAddress</code> points to a 64-bit value,
683 to compare the value of the most significant bit, you would specify
684 <code>56</code> for <code>__n</code>.
686 This function is equivalent to {@link OSAtomicTestAndSet}
687 except that it also introduces a barrier.
689 Returns the original value of the bit being tested.
691 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
692 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
693 bool OSAtomicTestAndSetBarrier( uint32_t __n
, volatile void *__theAddress
);
697 /*! @abstract Atomic test and clear
699 This function tests a bit in the value referenced by <code>__theAddress</code>
700 and if it is not cleared, clears it.
702 The bit is chosen by the value of <code>__n</code> such that the
703 operation will be performed on bit <code>(0x80 >> (__n & 7))</code>
704 of byte <code>((char *)__theAddress + (n >> 3))</code>.
706 For example, if <code>__theAddress</code> points to a 64-bit value,
707 to compare the value of the most significant bit, you would specify
708 <code>56</code> for <code>__n</code>.
711 Returns the original value of the bit being tested.
713 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
714 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
715 bool OSAtomicTestAndClear( uint32_t __n
, volatile void *__theAddress
);
718 /*! @abstract Atomic test and clear
720 This function tests a bit in the value referenced by <code>__theAddress</code>
721 and if it is not cleared, clears it.
723 The bit is chosen by the value of <code>__n</code> such that the
724 operation will be performed on bit <code>(0x80 >> (__n & 7))</code>
725 of byte <code>((char *)__theAddress + (n >> 3))</code>.
727 For example, if <code>__theAddress</code> points to a 64-bit value,
728 to compare the value of the most significant bit, you would specify
729 <code>56</code> for <code>__n</code>.
731 This function is equivalent to {@link OSAtomicTestAndSet}
732 except that it also introduces a barrier.
734 Returns the original value of the bit being tested.
736 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
737 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
738 bool OSAtomicTestAndClearBarrier( uint32_t __n
, volatile void *__theAddress
);
741 /*! @group Memory barriers */
743 /*! @abstract Memory barrier.
745 This function serves as both a read and write barrier.
747 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_thread_fence
)
748 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
749 void OSMemoryBarrier( void );
753 #else // defined(OSATOMIC_USE_INLINED) && OSATOMIC_USE_INLINED
756 * Inline implementations of the legacy OSAtomic interfaces in terms of
757 * C11 <stdatomic.h> resp. C++11 <atomic> primitives.
758 * Direct use of those primitives is preferred.
761 #include <sys/cdefs.h>
769 #if !(__has_include(<atomic>) && __has_feature(cxx_atomic))
770 #error Cannot use inlined OSAtomic without <atomic> and C++11 atomics
773 typedef std::atomic
<uint8_t> _OSAtomic_uint8_t
;
774 typedef std::atomic
<int32_t> _OSAtomic_int32_t
;
775 typedef std::atomic
<uint32_t> _OSAtomic_uint32_t
;
776 typedef std::atomic
<int64_t> _OSAtomic_int64_t
;
777 typedef std::atomic
<void*> _OSAtomic_void_ptr_t
;
778 #define OSATOMIC_STD(_a) std::_a
781 #if !(__has_include(<stdatomic.h>) && __has_extension(c_atomic))
782 #error Cannot use inlined OSAtomic without <stdatomic.h> and C11 atomics
784 #include <stdatomic.h>
785 typedef _Atomic(uint8_t) _OSAtomic_uint8_t
;
786 typedef _Atomic(int32_t) _OSAtomic_int32_t
;
787 typedef _Atomic(uint32_t) _OSAtomic_uint32_t
;
788 typedef _Atomic(int64_t) _OSAtomic_int64_t
;
789 typedef _Atomic(void*) _OSAtomic_void_ptr_t
;
790 #define OSATOMIC_STD(_a) _a
793 #if __has_extension(c_alignof) && __has_attribute(aligned)
794 typedef int64_t __attribute__((__aligned__(_Alignof(_OSAtomic_int64_t
))))
795 OSAtomic_int64_aligned64_t
;
796 #elif __has_attribute(aligned)
797 typedef int64_t __attribute__((__aligned__((sizeof(_OSAtomic_int64_t
)))))
798 OSAtomic_int64_aligned64_t
;
800 typedef int64_t OSAtomic_int64_aligned64_t
;
803 #if __has_attribute(always_inline)
804 #define OSATOMIC_INLINE static __inline
806 #define OSATOMIC_INLINE static __inline __attribute__((__always_inline__))
811 OSAtomicAdd32(int32_t __theAmount
, volatile int32_t *__theValue
)
813 return (OSATOMIC_STD(atomic_fetch_add_explicit
)(
814 (volatile _OSAtomic_int32_t
*) __theValue
, __theAmount
,
815 OSATOMIC_STD(memory_order_relaxed
)) + __theAmount
);
820 OSAtomicAdd32Barrier(int32_t __theAmount
, volatile int32_t *__theValue
)
822 return (OSATOMIC_STD(atomic_fetch_add_explicit
)(
823 (volatile _OSAtomic_int32_t
*) __theValue
, __theAmount
,
824 OSATOMIC_STD(memory_order_seq_cst
)) + __theAmount
);
829 OSAtomicIncrement32(volatile int32_t *__theValue
)
831 return OSAtomicAdd32(1, __theValue
);
836 OSAtomicIncrement32Barrier(volatile int32_t *__theValue
)
838 return OSAtomicAdd32Barrier(1, __theValue
);
843 OSAtomicDecrement32(volatile int32_t *__theValue
)
845 return OSAtomicAdd32(-1, __theValue
);
850 OSAtomicDecrement32Barrier(volatile int32_t *__theValue
)
852 return OSAtomicAdd32Barrier(-1, __theValue
);
857 OSAtomicAdd64(int64_t __theAmount
,
858 volatile OSAtomic_int64_aligned64_t
*__theValue
)
860 return (OSATOMIC_STD(atomic_fetch_add_explicit
)(
861 (volatile _OSAtomic_int64_t
*) __theValue
, __theAmount
,
862 OSATOMIC_STD(memory_order_relaxed
)) + __theAmount
);
867 OSAtomicAdd64Barrier(int64_t __theAmount
,
868 volatile OSAtomic_int64_aligned64_t
*__theValue
)
870 return (OSATOMIC_STD(atomic_fetch_add_explicit
)(
871 (volatile _OSAtomic_int64_t
*) __theValue
, __theAmount
,
872 OSATOMIC_STD(memory_order_seq_cst
)) + __theAmount
);
877 OSAtomicIncrement64(volatile OSAtomic_int64_aligned64_t
*__theValue
)
879 return OSAtomicAdd64(1, __theValue
);
884 OSAtomicIncrement64Barrier(volatile OSAtomic_int64_aligned64_t
*__theValue
)
886 return OSAtomicAdd64Barrier(1, __theValue
);
891 OSAtomicDecrement64(volatile OSAtomic_int64_aligned64_t
*__theValue
)
893 return OSAtomicAdd64(-1, __theValue
);
898 OSAtomicDecrement64Barrier(volatile OSAtomic_int64_aligned64_t
*__theValue
)
900 return OSAtomicAdd64Barrier(-1, __theValue
);
905 OSAtomicOr32(uint32_t __theMask
, volatile uint32_t *__theValue
)
907 return (int32_t)(OSATOMIC_STD(atomic_fetch_or_explicit
)(
908 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
909 OSATOMIC_STD(memory_order_relaxed
)) | __theMask
);
914 OSAtomicOr32Barrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
916 return (int32_t)(OSATOMIC_STD(atomic_fetch_or_explicit
)(
917 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
918 OSATOMIC_STD(memory_order_seq_cst
)) | __theMask
);
923 OSAtomicOr32Orig(uint32_t __theMask
, volatile uint32_t *__theValue
)
925 return (int32_t)(OSATOMIC_STD(atomic_fetch_or_explicit
)(
926 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
927 OSATOMIC_STD(memory_order_relaxed
)));
932 OSAtomicOr32OrigBarrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
934 return (int32_t)(OSATOMIC_STD(atomic_fetch_or_explicit
)(
935 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
936 OSATOMIC_STD(memory_order_seq_cst
)));
941 OSAtomicAnd32(uint32_t __theMask
, volatile uint32_t *__theValue
)
943 return (int32_t)(OSATOMIC_STD(atomic_fetch_and_explicit
)(
944 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
945 OSATOMIC_STD(memory_order_relaxed
)) & __theMask
);
950 OSAtomicAnd32Barrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
952 return (int32_t)(OSATOMIC_STD(atomic_fetch_and_explicit
)(
953 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
954 OSATOMIC_STD(memory_order_seq_cst
)) & __theMask
);
959 OSAtomicAnd32Orig(uint32_t __theMask
, volatile uint32_t *__theValue
)
961 return (int32_t)(OSATOMIC_STD(atomic_fetch_and_explicit
)(
962 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
963 OSATOMIC_STD(memory_order_relaxed
)));
968 OSAtomicAnd32OrigBarrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
970 return (int32_t)(OSATOMIC_STD(atomic_fetch_and_explicit
)(
971 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
972 OSATOMIC_STD(memory_order_seq_cst
)));
977 OSAtomicXor32(uint32_t __theMask
, volatile uint32_t *__theValue
)
979 return (int32_t)(OSATOMIC_STD(atomic_fetch_xor_explicit
)(
980 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
981 OSATOMIC_STD(memory_order_relaxed
)) ^ __theMask
);
986 OSAtomicXor32Barrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
988 return (int32_t)(OSATOMIC_STD(atomic_fetch_xor_explicit
)(
989 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
990 OSATOMIC_STD(memory_order_seq_cst
)) ^ __theMask
);
995 OSAtomicXor32Orig(uint32_t __theMask
, volatile uint32_t *__theValue
)
997 return (int32_t)(OSATOMIC_STD(atomic_fetch_xor_explicit
)(
998 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
999 OSATOMIC_STD(memory_order_relaxed
)));
1004 OSAtomicXor32OrigBarrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
1006 return (int32_t)(OSATOMIC_STD(atomic_fetch_xor_explicit
)(
1007 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
1008 OSATOMIC_STD(memory_order_seq_cst
)));
1013 OSAtomicCompareAndSwap32(int32_t __oldValue
, int32_t __newValue
,
1014 volatile int32_t *__theValue
)
1016 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1017 (volatile _OSAtomic_int32_t
*)__theValue
, &__oldValue
, __newValue
,
1018 OSATOMIC_STD(memory_order_relaxed
),
1019 OSATOMIC_STD(memory_order_relaxed
)));
1024 OSAtomicCompareAndSwap32Barrier(int32_t __oldValue
, int32_t __newValue
,
1025 volatile int32_t *__theValue
)
1027 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1028 (volatile _OSAtomic_int32_t
*)__theValue
, &__oldValue
, __newValue
,
1029 OSATOMIC_STD(memory_order_seq_cst
),
1030 OSATOMIC_STD(memory_order_relaxed
)));
1035 OSAtomicCompareAndSwapPtr(void *__oldValue
, void *__newValue
,
1036 void * volatile *__theValue
)
1038 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1039 (volatile _OSAtomic_void_ptr_t
*)__theValue
, &__oldValue
, __newValue
,
1040 OSATOMIC_STD(memory_order_relaxed
),
1041 OSATOMIC_STD(memory_order_relaxed
)));
1046 OSAtomicCompareAndSwapPtrBarrier(void *__oldValue
, void *__newValue
,
1047 void * volatile *__theValue
)
1049 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1050 (volatile _OSAtomic_void_ptr_t
*)__theValue
, &__oldValue
, __newValue
,
1051 OSATOMIC_STD(memory_order_seq_cst
),
1052 OSATOMIC_STD(memory_order_relaxed
)));
1057 OSAtomicCompareAndSwapInt(int __oldValue
, int __newValue
,
1058 volatile int *__theValue
)
1060 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1061 (volatile OSATOMIC_STD(atomic_int
)*)__theValue
, &__oldValue
,
1062 __newValue
, OSATOMIC_STD(memory_order_relaxed
),
1063 OSATOMIC_STD(memory_order_relaxed
)));
1068 OSAtomicCompareAndSwapIntBarrier(int __oldValue
, int __newValue
,
1069 volatile int *__theValue
)
1071 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1072 (volatile OSATOMIC_STD(atomic_int
)*)__theValue
, &__oldValue
,
1073 __newValue
, OSATOMIC_STD(memory_order_seq_cst
),
1074 OSATOMIC_STD(memory_order_relaxed
)));
1079 OSAtomicCompareAndSwapLong(long __oldValue
, long __newValue
,
1080 volatile long *__theValue
)
1082 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1083 (volatile OSATOMIC_STD(atomic_long
)*)__theValue
, &__oldValue
,
1084 __newValue
, OSATOMIC_STD(memory_order_relaxed
),
1085 OSATOMIC_STD(memory_order_relaxed
)));
1090 OSAtomicCompareAndSwapLongBarrier(long __oldValue
, long __newValue
,
1091 volatile long *__theValue
)
1093 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1094 (volatile OSATOMIC_STD(atomic_long
)*)__theValue
, &__oldValue
,
1095 __newValue
, OSATOMIC_STD(memory_order_seq_cst
),
1096 OSATOMIC_STD(memory_order_relaxed
)));
1101 OSAtomicCompareAndSwap64(int64_t __oldValue
, int64_t __newValue
,
1102 volatile OSAtomic_int64_aligned64_t
*__theValue
)
1104 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1105 (volatile _OSAtomic_int64_t
*)__theValue
, &__oldValue
, __newValue
,
1106 OSATOMIC_STD(memory_order_relaxed
),
1107 OSATOMIC_STD(memory_order_relaxed
)));
1112 OSAtomicCompareAndSwap64Barrier(int64_t __oldValue
, int64_t __newValue
,
1113 volatile OSAtomic_int64_aligned64_t
*__theValue
)
1115 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1116 (volatile _OSAtomic_int64_t
*)__theValue
, &__oldValue
, __newValue
,
1117 OSATOMIC_STD(memory_order_seq_cst
),
1118 OSATOMIC_STD(memory_order_relaxed
)));
1123 OSAtomicTestAndSet(uint32_t __n
, volatile void *__theAddress
)
1125 uintptr_t a
= (uintptr_t)__theAddress
+ (__n
>> 3);
1126 uint8_t v
= (0x80u
>> (__n
& 7));
1127 return (OSATOMIC_STD(atomic_fetch_or_explicit
)((_OSAtomic_uint8_t
*)a
, v
,
1128 OSATOMIC_STD(memory_order_relaxed
)) & v
);
1133 OSAtomicTestAndSetBarrier(uint32_t __n
, volatile void *__theAddress
)
1135 uintptr_t a
= (uintptr_t)__theAddress
+ (__n
>> 3);
1136 uint8_t v
= (0x80u
>> (__n
& 7));
1137 return (OSATOMIC_STD(atomic_fetch_or_explicit
)((_OSAtomic_uint8_t
*)a
, v
,
1138 OSATOMIC_STD(memory_order_seq_cst
)) & v
);
1143 OSAtomicTestAndClear(uint32_t __n
, volatile void *__theAddress
)
1145 uintptr_t a
= (uintptr_t)__theAddress
+ (__n
>> 3);
1146 uint8_t v
= (0x80u
>> (__n
& 7));
1147 return (OSATOMIC_STD(atomic_fetch_and_explicit
)((_OSAtomic_uint8_t
*)a
,
1148 (uint8_t)~v
, OSATOMIC_STD(memory_order_relaxed
)) & v
);
1153 OSAtomicTestAndClearBarrier(uint32_t __n
, volatile void *__theAddress
)
1155 uintptr_t a
= (uintptr_t)__theAddress
+ (__n
>> 3);
1156 uint8_t v
= (0x80u
>> (__n
& 7));
1157 return (OSATOMIC_STD(atomic_fetch_and_explicit
)((_OSAtomic_uint8_t
*)a
,
1158 (uint8_t)~v
, OSATOMIC_STD(memory_order_seq_cst
)) & v
);
1163 OSMemoryBarrier(void)
1165 OSATOMIC_STD(atomic_thread_fence
)(OSATOMIC_STD(memory_order_seq_cst
));
1168 #undef OSATOMIC_INLINE
1175 #endif // defined(OSATOMIC_USE_INLINED) && OSATOMIC_USE_INLINED
1177 #endif /* _OSATOMIC_DEPRECATED_H_ */