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 #include <Availability.h>
40 #if !(defined(OSATOMIC_USE_INLINED) && OSATOMIC_USE_INLINED)
42 #include <sys/cdefs.h>
47 #ifndef OSATOMIC_DEPRECATED
48 #define OSATOMIC_DEPRECATED 1
50 #define OSATOMIC_BARRIER_DEPRECATED_MSG(_r) \
51 "Use " #_r "() from <stdatomic.h> instead"
52 #define OSATOMIC_DEPRECATED_MSG(_r) \
53 "Use " #_r "_explicit(memory_order_relaxed) from <stdatomic.h> instead"
55 #define OSATOMIC_BARRIER_DEPRECATED_MSG(_r) \
56 "Use std::" #_r "() from <atomic> instead"
57 #define OSATOMIC_DEPRECATED_MSG(_r) \
58 "Use std::" #_r "_explicit(std::memory_order_relaxed) from <atomic> instead"
60 #define OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(_r) \
61 __OS_AVAILABILITY_MSG(macosx, deprecated=10.12, OSATOMIC_BARRIER_DEPRECATED_MSG(_r)) \
62 __OS_AVAILABILITY_MSG(ios, deprecated=10.0, OSATOMIC_BARRIER_DEPRECATED_MSG(_r)) \
63 __OS_AVAILABILITY_MSG(tvos, deprecated=10.0, OSATOMIC_BARRIER_DEPRECATED_MSG(_r)) \
64 __OS_AVAILABILITY_MSG(watchos, deprecated=3.0, OSATOMIC_BARRIER_DEPRECATED_MSG(_r))
65 #define OSATOMIC_DEPRECATED_REPLACE_WITH(_r) \
66 __OS_AVAILABILITY_MSG(macosx, deprecated=10.12, OSATOMIC_DEPRECATED_MSG(_r)) \
67 __OS_AVAILABILITY_MSG(ios, deprecated=10.0, OSATOMIC_DEPRECATED_MSG(_r)) \
68 __OS_AVAILABILITY_MSG(tvos, deprecated=10.0, OSATOMIC_DEPRECATED_MSG(_r)) \
69 __OS_AVAILABILITY_MSG(watchos, deprecated=3.0, OSATOMIC_DEPRECATED_MSG(_r))
71 #undef OSATOMIC_DEPRECATED
72 #define OSATOMIC_DEPRECATED 0
73 #define OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(_r)
74 #define OSATOMIC_DEPRECATED_REPLACE_WITH(_r)
78 * WARNING: all addresses passed to these functions must be "naturally aligned",
79 * i.e. <code>int32_t</code> pointers must be 32-bit aligned (low 2 bits of
80 * address are zeroes), and <code>int64_t</code> pointers must be 64-bit
81 * aligned (low 3 bits of address are zeroes.).
82 * Note that this is not the default alignment of the <code>int64_t</code> type
83 * in the iOS ARMv7 ABI, see
84 * {@link //apple_ref/doc/uid/TP40009021-SW8 iPhoneOSABIReference}
86 * Note that some versions of the atomic functions incorporate memory barriers
87 * and some do not. Barriers strictly order memory access on weakly-ordered
88 * architectures such as ARM. All loads and stores that appear (in sequential
89 * program order) before the barrier are guaranteed to complete before any
90 * load or store that appears after the barrier.
92 * The barrier operation is typically a no-op on uniprocessor systems and
93 * fully enabled on multiprocessor systems. On some platforms, such as ARM,
94 * the barrier can be quite expensive.
96 * Most code should use the barrier functions to ensure that memory shared
97 * between threads is properly synchronized. For example, if you want to
98 * initialize a shared data structure and then atomically increment a variable
99 * to indicate that the initialization is complete, you must use
100 * {@link OSAtomicIncrement32Barrier} to ensure that the stores to your data
101 * structure complete before the atomic increment.
103 * Likewise, the consumer of that data structure must use
104 * {@link OSAtomicDecrement32Barrier},
105 * in order to ensure that their loads of the structure are not executed before
106 * the atomic decrement. On the other hand, if you are simply incrementing a
107 * global counter, then it is safe and potentially faster to use
108 * {@link OSAtomicIncrement32}.
110 * If you are unsure which version to use, prefer the barrier variants as they
113 * For the kernel-space version of this header, see
114 * {@link //apple_ref/doc/header/OSAtomic.h OSAtomic.h (Kernel Framework)}
116 * @apiuid //apple_ref/doc/header/user_space_OSAtomic.h
121 /*! @typedef OSAtomic_int64_aligned64_t
122 * 64-bit aligned <code>int64_t</code> type.
123 * Use for variables whose addresses are passed to OSAtomic*64() functions to
124 * get the compiler to generate the required alignment.
127 #if __has_attribute(aligned)
128 typedef int64_t __attribute__((__aligned__((sizeof(int64_t)))))
129 OSAtomic_int64_aligned64_t
;
131 typedef int64_t OSAtomic_int64_aligned64_t
;
134 /*! @group Arithmetic functions
135 All functions in this group return the new value.
138 /*! @abstract Atomically adds two 32-bit values.
140 This function adds the value given by <code>__theAmount</code> to the
141 value in the memory location referenced by <code>__theValue</code>,
142 storing the result back to that memory location atomically.
143 @result Returns the new value.
145 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
146 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
147 int32_t OSAtomicAdd32( int32_t __theAmount
, volatile int32_t *__theValue
);
150 /*! @abstract Atomically adds two 32-bit values.
152 This function adds the value given by <code>__theAmount</code> to the
153 value in the memory location referenced by <code>__theValue</code>,
154 storing the result back to that memory location atomically.
156 This function is equivalent to {@link OSAtomicAdd32}
157 except that it also introduces a barrier.
158 @result Returns the new value.
160 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
161 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
162 int32_t OSAtomicAdd32Barrier( int32_t __theAmount
, volatile int32_t *__theValue
);
165 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10 || __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_7_1 || TARGET_OS_DRIVERKIT
167 /*! @abstract Atomically increments a 32-bit value.
168 @result Returns the new value.
170 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
171 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
172 int32_t OSAtomicIncrement32( volatile int32_t *__theValue
);
175 /*! @abstract Atomically increments a 32-bit value with a barrier.
177 This function is equivalent to {@link OSAtomicIncrement32}
178 except that it also introduces a barrier.
179 @result Returns the new value.
181 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
182 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
183 int32_t OSAtomicIncrement32Barrier( volatile int32_t *__theValue
);
186 /*! @abstract Atomically decrements a 32-bit value.
187 @result Returns the new value.
189 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_sub
)
190 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
191 int32_t OSAtomicDecrement32( volatile int32_t *__theValue
);
194 /*! @abstract Atomically decrements a 32-bit value with a barrier.
196 This function is equivalent to {@link OSAtomicDecrement32}
197 except that it also introduces a barrier.
198 @result Returns the new value.
200 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_sub
)
201 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
202 int32_t OSAtomicDecrement32Barrier( volatile int32_t *__theValue
);
206 int32_t OSAtomicIncrement32( volatile int32_t *__theValue
)
207 { return OSAtomicAdd32( 1, __theValue
); }
210 int32_t OSAtomicIncrement32Barrier( volatile int32_t *__theValue
)
211 { return OSAtomicAdd32Barrier( 1, __theValue
); }
214 int32_t OSAtomicDecrement32( volatile int32_t *__theValue
)
215 { return OSAtomicAdd32( -1, __theValue
); }
218 int32_t OSAtomicDecrement32Barrier( volatile int32_t *__theValue
)
219 { return OSAtomicAdd32Barrier( -1, __theValue
); }
223 /*! @abstract Atomically adds two 64-bit values.
225 This function adds the value given by <code>__theAmount</code> to the
226 value in the memory location referenced by <code>__theValue</code>,
227 storing the result back to that memory location atomically.
228 @result Returns the new value.
230 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
231 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
232 int64_t OSAtomicAdd64( int64_t __theAmount
,
233 volatile OSAtomic_int64_aligned64_t
*__theValue
);
236 /*! @abstract Atomically adds two 64-bit values with a barrier.
238 This function adds the value given by <code>__theAmount</code> to the
239 value in the memory location referenced by <code>__theValue</code>,
240 storing the result back to that memory location atomically.
242 This function is equivalent to {@link OSAtomicAdd64}
243 except that it also introduces a barrier.
244 @result Returns the new value.
246 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
247 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_3_2
)
248 int64_t OSAtomicAdd64Barrier( int64_t __theAmount
,
249 volatile OSAtomic_int64_aligned64_t
*__theValue
);
252 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10 || __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_7_1 || TARGET_OS_DRIVERKIT
254 /*! @abstract Atomically increments a 64-bit value.
255 @result Returns the new value.
257 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
258 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
259 int64_t OSAtomicIncrement64( volatile OSAtomic_int64_aligned64_t
*__theValue
);
262 /*! @abstract Atomically increments a 64-bit value with a barrier.
264 This function is equivalent to {@link OSAtomicIncrement64}
265 except that it also introduces a barrier.
266 @result Returns the new value.
268 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_add
)
269 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
270 int64_t OSAtomicIncrement64Barrier( volatile OSAtomic_int64_aligned64_t
*__theValue
);
273 /*! @abstract Atomically decrements a 64-bit value.
274 @result Returns the new value.
276 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_sub
)
277 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
278 int64_t OSAtomicDecrement64( volatile OSAtomic_int64_aligned64_t
*__theValue
);
281 /*! @abstract Atomically decrements a 64-bit value with a barrier.
283 This function is equivalent to {@link OSAtomicDecrement64}
284 except that it also introduces a barrier.
285 @result Returns the new value.
287 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_sub
)
288 __OSX_AVAILABLE_STARTING(__MAC_10_10
, __IPHONE_7_1
)
289 int64_t OSAtomicDecrement64Barrier( volatile OSAtomic_int64_aligned64_t
*__theValue
);
293 int64_t OSAtomicIncrement64( volatile OSAtomic_int64_aligned64_t
*__theValue
)
294 { return OSAtomicAdd64( 1, __theValue
); }
297 int64_t OSAtomicIncrement64Barrier( volatile OSAtomic_int64_aligned64_t
*__theValue
)
298 { return OSAtomicAdd64Barrier( 1, __theValue
); }
301 int64_t OSAtomicDecrement64( volatile OSAtomic_int64_aligned64_t
*__theValue
)
302 { return OSAtomicAdd64( -1, __theValue
); }
305 int64_t OSAtomicDecrement64Barrier( volatile OSAtomic_int64_aligned64_t
*__theValue
)
306 { return OSAtomicAdd64Barrier( -1, __theValue
); }
310 /*! @group Boolean functions (AND, OR, XOR)
312 * @discussion Functions in this group come in four variants for each operation:
313 * with and without barriers, and functions that return the original value or
314 * the result value of the operation.
316 * The "Orig" versions return the original value, (before the operation); the non-Orig
317 * versions return the value after the operation. All are layered on top of
318 * {@link OSAtomicCompareAndSwap32} and similar.
321 /*! @abstract Atomic bitwise OR of two 32-bit values.
323 This function performs the bitwise OR of the value given by <code>__theMask</code>
324 with the value in the memory location referenced by <code>__theValue</code>,
325 storing the result back to that memory location atomically.
326 @result Returns the new value.
328 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
329 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
330 int32_t OSAtomicOr32( uint32_t __theMask
, volatile uint32_t *__theValue
);
333 /*! @abstract Atomic bitwise OR of two 32-bit values with barrier.
335 This function performs the bitwise OR of the value given by <code>__theMask</code>
336 with the value in the memory location referenced by <code>__theValue</code>,
337 storing the result back to that memory location atomically.
339 This function is equivalent to {@link OSAtomicOr32}
340 except that it also introduces a barrier.
341 @result Returns the new value.
343 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
344 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
345 int32_t OSAtomicOr32Barrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
348 /*! @abstract Atomic bitwise OR of two 32-bit values returning original.
350 This function performs the bitwise OR of the value given by <code>__theMask</code>
351 with the value in the memory location referenced by <code>__theValue</code>,
352 storing the result back to that memory location atomically.
353 @result Returns the original value referenced by <code>__theValue</code>.
355 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
356 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
357 int32_t OSAtomicOr32Orig( uint32_t __theMask
, volatile uint32_t *__theValue
);
360 /*! @abstract Atomic bitwise OR of two 32-bit values returning original with barrier.
362 This function performs the bitwise OR of the value given by <code>__theMask</code>
363 with the value in the memory location referenced by <code>__theValue</code>,
364 storing the result back to that memory location atomically.
366 This function is equivalent to {@link OSAtomicOr32Orig}
367 except that it also introduces a barrier.
368 @result Returns the original value referenced by <code>__theValue</code>.
370 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
371 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
372 int32_t OSAtomicOr32OrigBarrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
377 /*! @abstract Atomic bitwise AND of two 32-bit values.
379 This function performs the bitwise AND of the value given by <code>__theMask</code>
380 with the value in the memory location referenced by <code>__theValue</code>,
381 storing the result back to that memory location atomically.
382 @result Returns the new value.
384 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
385 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
386 int32_t OSAtomicAnd32( uint32_t __theMask
, volatile uint32_t *__theValue
);
389 /*! @abstract Atomic bitwise AND of two 32-bit values with barrier.
391 This function performs the bitwise AND of the value given by <code>__theMask</code>
392 with the value in the memory location referenced by <code>__theValue</code>,
393 storing the result back to that memory location atomically.
395 This function is equivalent to {@link OSAtomicAnd32}
396 except that it also introduces a barrier.
397 @result Returns the new value.
399 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
400 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
401 int32_t OSAtomicAnd32Barrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
404 /*! @abstract Atomic bitwise AND of two 32-bit values returning original.
406 This function performs the bitwise AND of the value given by <code>__theMask</code>
407 with the value in the memory location referenced by <code>__theValue</code>,
408 storing the result back to that memory location atomically.
409 @result Returns the original value referenced by <code>__theValue</code>.
411 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
412 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
413 int32_t OSAtomicAnd32Orig( uint32_t __theMask
, volatile uint32_t *__theValue
);
416 /*! @abstract Atomic bitwise AND of two 32-bit values returning original with barrier.
418 This function performs the bitwise AND of the value given by <code>__theMask</code>
419 with the value in the memory location referenced by <code>__theValue</code>,
420 storing the result back to that memory location atomically.
422 This function is equivalent to {@link OSAtomicAnd32Orig}
423 except that it also introduces a barrier.
424 @result Returns the original value referenced by <code>__theValue</code>.
426 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
427 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
428 int32_t OSAtomicAnd32OrigBarrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
433 /*! @abstract Atomic bitwise XOR of two 32-bit values.
435 This function performs the bitwise XOR of the value given by <code>__theMask</code>
436 with the value in the memory location referenced by <code>__theValue</code>,
437 storing the result back to that memory location atomically.
438 @result Returns the new value.
440 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_xor
)
441 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
442 int32_t OSAtomicXor32( uint32_t __theMask
, volatile uint32_t *__theValue
);
445 /*! @abstract Atomic bitwise XOR of two 32-bit values with barrier.
447 This function performs the bitwise XOR of the value given by <code>__theMask</code>
448 with the value in the memory location referenced by <code>__theValue</code>,
449 storing the result back to that memory location atomically.
451 This function is equivalent to {@link OSAtomicXor32}
452 except that it also introduces a barrier.
453 @result Returns the new value.
455 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_xor
)
456 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
457 int32_t OSAtomicXor32Barrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
460 /*! @abstract Atomic bitwise XOR of two 32-bit values returning original.
462 This function performs the bitwise XOR of the value given by <code>__theMask</code>
463 with the value in the memory location referenced by <code>__theValue</code>,
464 storing the result back to that memory location atomically.
465 @result Returns the original value referenced by <code>__theValue</code>.
467 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_xor
)
468 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
469 int32_t OSAtomicXor32Orig( uint32_t __theMask
, volatile uint32_t *__theValue
);
472 /*! @abstract Atomic bitwise XOR of two 32-bit values returning original with barrier.
474 This function performs the bitwise XOR of the value given by <code>__theMask</code>
475 with the value in the memory location referenced by <code>__theValue</code>,
476 storing the result back to that memory location atomically.
478 This function is equivalent to {@link OSAtomicXor32Orig}
479 except that it also introduces a barrier.
480 @result Returns the original value referenced by <code>__theValue</code>.
482 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_xor
)
483 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_3_2
)
484 int32_t OSAtomicXor32OrigBarrier( uint32_t __theMask
, volatile uint32_t *__theValue
);
487 /*! @group Compare and swap
488 * Functions in this group return true if the swap occured. There are several versions,
489 * depending on data type and on whether or not a barrier is used.
493 /*! @abstract Compare and swap for 32-bit values.
495 This function compares the value in <code>__oldValue</code> to the value
496 in the memory location referenced by <code>__theValue</code>. If the values
497 match, this function stores the value from <code>__newValue</code> into
498 that memory location atomically.
499 @result Returns TRUE on a match, FALSE otherwise.
501 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
502 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
503 bool OSAtomicCompareAndSwap32( int32_t __oldValue
, int32_t __newValue
, volatile int32_t *__theValue
);
506 /*! @abstract Compare and swap for 32-bit values with barrier.
508 This function compares the value in <code>__oldValue</code> to the value
509 in the memory location referenced by <code>__theValue</code>. If the values
510 match, this function stores the value from <code>__newValue</code> into
511 that memory location atomically.
513 This function is equivalent to {@link OSAtomicCompareAndSwap32}
514 except that it also introduces a barrier.
515 @result Returns TRUE on a match, FALSE otherwise.
517 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
518 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
519 bool OSAtomicCompareAndSwap32Barrier( int32_t __oldValue
, int32_t __newValue
, volatile int32_t *__theValue
);
522 /*! @abstract Compare and swap pointers.
524 This function compares the pointer stored in <code>__oldValue</code> to the pointer
525 in the memory location referenced by <code>__theValue</code>. If the pointers
526 match, this function stores the pointer from <code>__newValue</code> into
527 that memory location atomically.
528 @result Returns TRUE on a match, FALSE otherwise.
530 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
531 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
532 bool OSAtomicCompareAndSwapPtr( void *__oldValue
, void *__newValue
, void * volatile *__theValue
);
535 /*! @abstract Compare and swap pointers with barrier.
537 This function compares the pointer stored in <code>__oldValue</code> to the pointer
538 in the memory location referenced by <code>__theValue</code>. If the pointers
539 match, this function stores the pointer from <code>__newValue</code> into
540 that memory location atomically.
542 This function is equivalent to {@link OSAtomicCompareAndSwapPtr}
543 except that it also introduces a barrier.
544 @result Returns TRUE on a match, FALSE otherwise.
546 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
547 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
548 bool OSAtomicCompareAndSwapPtrBarrier( void *__oldValue
, void *__newValue
, void * volatile *__theValue
);
551 /*! @abstract Compare and swap for <code>int</code> values.
553 This function compares the value in <code>__oldValue</code> to the value
554 in the memory location referenced by <code>__theValue</code>. If the values
555 match, this function stores the value from <code>__newValue</code> into
556 that memory location atomically.
558 This function is equivalent to {@link OSAtomicCompareAndSwap32}.
559 @result Returns TRUE on a match, FALSE otherwise.
561 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
562 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
563 bool OSAtomicCompareAndSwapInt( int __oldValue
, int __newValue
, volatile int *__theValue
);
566 /*! @abstract Compare and swap for <code>int</code> values.
568 This function compares the value in <code>__oldValue</code> to the value
569 in the memory location referenced by <code>__theValue</code>. If the values
570 match, this function stores the value from <code>__newValue</code> into
571 that memory location atomically.
573 This function is equivalent to {@link OSAtomicCompareAndSwapInt}
574 except that it also introduces a barrier.
576 This function is equivalent to {@link OSAtomicCompareAndSwap32Barrier}.
577 @result Returns TRUE on a match, FALSE otherwise.
579 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
580 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
581 bool OSAtomicCompareAndSwapIntBarrier( int __oldValue
, int __newValue
, volatile int *__theValue
);
584 /*! @abstract Compare and swap for <code>long</code> values.
586 This function compares the value in <code>__oldValue</code> to the value
587 in the memory location referenced by <code>__theValue</code>. If the values
588 match, this function stores the value from <code>__newValue</code> into
589 that memory location atomically.
591 This function is equivalent to {@link OSAtomicCompareAndSwap32} on 32-bit architectures,
592 or {@link OSAtomicCompareAndSwap64} on 64-bit architectures.
593 @result Returns TRUE on a match, FALSE otherwise.
595 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
596 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
597 bool OSAtomicCompareAndSwapLong( long __oldValue
, long __newValue
, volatile long *__theValue
);
600 /*! @abstract Compare and swap for <code>long</code> values.
602 This function compares the value in <code>__oldValue</code> to the value
603 in the memory location referenced by <code>__theValue</code>. If the values
604 match, this function stores the value from <code>__newValue</code> into
605 that memory location atomically.
607 This function is equivalent to {@link OSAtomicCompareAndSwapLong}
608 except that it also introduces a barrier.
610 This function is equivalent to {@link OSAtomicCompareAndSwap32} on 32-bit architectures,
611 or {@link OSAtomicCompareAndSwap64} on 64-bit architectures.
612 @result Returns TRUE on a match, FALSE otherwise.
614 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
615 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_2_0
)
616 bool OSAtomicCompareAndSwapLongBarrier( long __oldValue
, long __newValue
, volatile long *__theValue
);
619 /*! @abstract Compare and swap for <code>uint64_t</code> values.
621 This function compares the value in <code>__oldValue</code> to the value
622 in the memory location referenced by <code>__theValue</code>. If the values
623 match, this function stores the value from <code>__newValue</code> into
624 that memory location atomically.
625 @result Returns TRUE on a match, FALSE otherwise.
627 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
628 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
629 bool OSAtomicCompareAndSwap64( int64_t __oldValue
, int64_t __newValue
,
630 volatile OSAtomic_int64_aligned64_t
*__theValue
);
633 /*! @abstract Compare and swap for <code>uint64_t</code> values.
635 This function compares the value in <code>__oldValue</code> to the value
636 in the memory location referenced by <code>__theValue</code>. If the values
637 match, this function stores the value from <code>__newValue</code> into
638 that memory location atomically.
640 This function is equivalent to {@link OSAtomicCompareAndSwap64}
641 except that it also introduces a barrier.
642 @result Returns TRUE on a match, FALSE otherwise.
644 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_compare_exchange_strong
)
645 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_3_2
)
646 bool OSAtomicCompareAndSwap64Barrier( int64_t __oldValue
, int64_t __newValue
,
647 volatile OSAtomic_int64_aligned64_t
*__theValue
);
651 * They return the original value of the bit, and operate on bit (0x80>>(n&7))
652 * in byte ((char*)theAddress + (n>>3)).
654 /*! @abstract Atomic test and set
656 This function tests a bit in the value referenced by
657 <code>__theAddress</code> and if it is not set, sets it.
659 The bit is chosen by the value of <code>__n</code> such that the
660 operation will be performed on bit <code>(0x80 >> (__n & 7))</code>
661 of byte <code>((char *)__theAddress + (n >> 3))</code>.
663 For example, if <code>__theAddress</code> points to a 64-bit value,
664 to compare the value of the most significant bit, you would specify
665 <code>56</code> for <code>__n</code>.
667 Returns the original value of the bit being tested.
669 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
670 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
671 bool OSAtomicTestAndSet( uint32_t __n
, volatile void *__theAddress
);
674 /*! @abstract Atomic test and set with barrier
676 This function tests a bit in the value referenced by <code>__theAddress</code>
677 and if it is not set, sets it.
679 The bit is chosen by the value of <code>__n</code> such that the
680 operation will be performed on bit <code>(0x80 >> (__n & 7))</code>
681 of byte <code>((char *)__theAddress + (n >> 3))</code>.
683 For example, if <code>__theAddress</code> points to a 64-bit value,
684 to compare the value of the most significant bit, you would specify
685 <code>56</code> for <code>__n</code>.
687 This function is equivalent to {@link OSAtomicTestAndSet}
688 except that it also introduces a barrier.
690 Returns the original value of the bit being tested.
692 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_or
)
693 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
694 bool OSAtomicTestAndSetBarrier( uint32_t __n
, volatile void *__theAddress
);
698 /*! @abstract Atomic test and clear
700 This function tests a bit in the value referenced by <code>__theAddress</code>
701 and if it is not cleared, clears it.
703 The bit is chosen by the value of <code>__n</code> such that the
704 operation will be performed on bit <code>(0x80 >> (__n & 7))</code>
705 of byte <code>((char *)__theAddress + (n >> 3))</code>.
707 For example, if <code>__theAddress</code> points to a 64-bit value,
708 to compare the value of the most significant bit, you would specify
709 <code>56</code> for <code>__n</code>.
712 Returns the original value of the bit being tested.
714 OSATOMIC_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
715 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
716 bool OSAtomicTestAndClear( uint32_t __n
, volatile void *__theAddress
);
719 /*! @abstract Atomic test and clear
721 This function tests a bit in the value referenced by <code>__theAddress</code>
722 and if it is not cleared, clears it.
724 The bit is chosen by the value of <code>__n</code> such that the
725 operation will be performed on bit <code>(0x80 >> (__n & 7))</code>
726 of byte <code>((char *)__theAddress + (n >> 3))</code>.
728 For example, if <code>__theAddress</code> points to a 64-bit value,
729 to compare the value of the most significant bit, you would specify
730 <code>56</code> for <code>__n</code>.
732 This function is equivalent to {@link OSAtomicTestAndSet}
733 except that it also introduces a barrier.
735 Returns the original value of the bit being tested.
737 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_fetch_and
)
738 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
739 bool OSAtomicTestAndClearBarrier( uint32_t __n
, volatile void *__theAddress
);
742 /*! @group Memory barriers */
744 /*! @abstract Memory barrier.
746 This function serves as both a read and write barrier.
748 OSATOMIC_BARRIER_DEPRECATED_REPLACE_WITH(atomic_thread_fence
)
749 __OSX_AVAILABLE_STARTING(__MAC_10_4
, __IPHONE_2_0
)
750 void OSMemoryBarrier( void );
754 #else // defined(OSATOMIC_USE_INLINED) && OSATOMIC_USE_INLINED
757 * Inline implementations of the legacy OSAtomic interfaces in terms of
758 * C11 <stdatomic.h> resp. C++11 <atomic> primitives.
759 * Direct use of those primitives is preferred.
762 #include <sys/cdefs.h>
770 #if !(__has_include(<atomic>) && __has_extension(cxx_atomic))
771 #error Cannot use inlined OSAtomic without <atomic> and C++11 atomics
774 typedef std::atomic
<uint8_t> _OSAtomic_uint8_t
;
775 typedef std::atomic
<int32_t> _OSAtomic_int32_t
;
776 typedef std::atomic
<uint32_t> _OSAtomic_uint32_t
;
777 typedef std::atomic
<int64_t> _OSAtomic_int64_t
;
778 typedef std::atomic
<void*> _OSAtomic_void_ptr_t
;
779 #define OSATOMIC_STD(_a) std::_a
782 #if !(__has_include(<stdatomic.h>) && __has_extension(c_atomic))
783 #error Cannot use inlined OSAtomic without <stdatomic.h> and C11 atomics
785 #include <stdatomic.h>
786 typedef _Atomic(uint8_t) _OSAtomic_uint8_t
;
787 typedef _Atomic(int32_t) _OSAtomic_int32_t
;
788 typedef _Atomic(uint32_t) _OSAtomic_uint32_t
;
789 typedef _Atomic(int64_t) _OSAtomic_int64_t
;
790 typedef _Atomic(void*) _OSAtomic_void_ptr_t
;
791 #define OSATOMIC_STD(_a) _a
794 #if __has_extension(c_alignof) && __has_attribute(aligned)
795 typedef int64_t __attribute__((__aligned__(_Alignof(_OSAtomic_int64_t
))))
796 OSAtomic_int64_aligned64_t
;
797 #elif __has_attribute(aligned)
798 typedef int64_t __attribute__((__aligned__((sizeof(_OSAtomic_int64_t
)))))
799 OSAtomic_int64_aligned64_t
;
801 typedef int64_t OSAtomic_int64_aligned64_t
;
804 #if __has_attribute(always_inline)
805 #define OSATOMIC_INLINE static __inline __attribute__((__always_inline__))
807 #define OSATOMIC_INLINE static __inline
812 OSAtomicAdd32(int32_t __theAmount
, volatile int32_t *__theValue
)
814 return (OSATOMIC_STD(atomic_fetch_add_explicit
)(
815 (volatile _OSAtomic_int32_t
*) __theValue
, __theAmount
,
816 OSATOMIC_STD(memory_order_relaxed
)) + __theAmount
);
821 OSAtomicAdd32Barrier(int32_t __theAmount
, volatile int32_t *__theValue
)
823 return (OSATOMIC_STD(atomic_fetch_add_explicit
)(
824 (volatile _OSAtomic_int32_t
*) __theValue
, __theAmount
,
825 OSATOMIC_STD(memory_order_seq_cst
)) + __theAmount
);
830 OSAtomicIncrement32(volatile int32_t *__theValue
)
832 return OSAtomicAdd32(1, __theValue
);
837 OSAtomicIncrement32Barrier(volatile int32_t *__theValue
)
839 return OSAtomicAdd32Barrier(1, __theValue
);
844 OSAtomicDecrement32(volatile int32_t *__theValue
)
846 return OSAtomicAdd32(-1, __theValue
);
851 OSAtomicDecrement32Barrier(volatile int32_t *__theValue
)
853 return OSAtomicAdd32Barrier(-1, __theValue
);
858 OSAtomicAdd64(int64_t __theAmount
,
859 volatile OSAtomic_int64_aligned64_t
*__theValue
)
861 return (OSATOMIC_STD(atomic_fetch_add_explicit
)(
862 (volatile _OSAtomic_int64_t
*) __theValue
, __theAmount
,
863 OSATOMIC_STD(memory_order_relaxed
)) + __theAmount
);
868 OSAtomicAdd64Barrier(int64_t __theAmount
,
869 volatile OSAtomic_int64_aligned64_t
*__theValue
)
871 return (OSATOMIC_STD(atomic_fetch_add_explicit
)(
872 (volatile _OSAtomic_int64_t
*) __theValue
, __theAmount
,
873 OSATOMIC_STD(memory_order_seq_cst
)) + __theAmount
);
878 OSAtomicIncrement64(volatile OSAtomic_int64_aligned64_t
*__theValue
)
880 return OSAtomicAdd64(1, __theValue
);
885 OSAtomicIncrement64Barrier(volatile OSAtomic_int64_aligned64_t
*__theValue
)
887 return OSAtomicAdd64Barrier(1, __theValue
);
892 OSAtomicDecrement64(volatile OSAtomic_int64_aligned64_t
*__theValue
)
894 return OSAtomicAdd64(-1, __theValue
);
899 OSAtomicDecrement64Barrier(volatile OSAtomic_int64_aligned64_t
*__theValue
)
901 return OSAtomicAdd64Barrier(-1, __theValue
);
906 OSAtomicOr32(uint32_t __theMask
, volatile uint32_t *__theValue
)
908 return (int32_t)(OSATOMIC_STD(atomic_fetch_or_explicit
)(
909 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
910 OSATOMIC_STD(memory_order_relaxed
)) | __theMask
);
915 OSAtomicOr32Barrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
917 return (int32_t)(OSATOMIC_STD(atomic_fetch_or_explicit
)(
918 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
919 OSATOMIC_STD(memory_order_seq_cst
)) | __theMask
);
924 OSAtomicOr32Orig(uint32_t __theMask
, volatile uint32_t *__theValue
)
926 return (int32_t)(OSATOMIC_STD(atomic_fetch_or_explicit
)(
927 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
928 OSATOMIC_STD(memory_order_relaxed
)));
933 OSAtomicOr32OrigBarrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
935 return (int32_t)(OSATOMIC_STD(atomic_fetch_or_explicit
)(
936 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
937 OSATOMIC_STD(memory_order_seq_cst
)));
942 OSAtomicAnd32(uint32_t __theMask
, volatile uint32_t *__theValue
)
944 return (int32_t)(OSATOMIC_STD(atomic_fetch_and_explicit
)(
945 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
946 OSATOMIC_STD(memory_order_relaxed
)) & __theMask
);
951 OSAtomicAnd32Barrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
953 return (int32_t)(OSATOMIC_STD(atomic_fetch_and_explicit
)(
954 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
955 OSATOMIC_STD(memory_order_seq_cst
)) & __theMask
);
960 OSAtomicAnd32Orig(uint32_t __theMask
, volatile uint32_t *__theValue
)
962 return (int32_t)(OSATOMIC_STD(atomic_fetch_and_explicit
)(
963 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
964 OSATOMIC_STD(memory_order_relaxed
)));
969 OSAtomicAnd32OrigBarrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
971 return (int32_t)(OSATOMIC_STD(atomic_fetch_and_explicit
)(
972 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
973 OSATOMIC_STD(memory_order_seq_cst
)));
978 OSAtomicXor32(uint32_t __theMask
, volatile uint32_t *__theValue
)
980 return (int32_t)(OSATOMIC_STD(atomic_fetch_xor_explicit
)(
981 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
982 OSATOMIC_STD(memory_order_relaxed
)) ^ __theMask
);
987 OSAtomicXor32Barrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
989 return (int32_t)(OSATOMIC_STD(atomic_fetch_xor_explicit
)(
990 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
991 OSATOMIC_STD(memory_order_seq_cst
)) ^ __theMask
);
996 OSAtomicXor32Orig(uint32_t __theMask
, volatile uint32_t *__theValue
)
998 return (int32_t)(OSATOMIC_STD(atomic_fetch_xor_explicit
)(
999 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
1000 OSATOMIC_STD(memory_order_relaxed
)));
1005 OSAtomicXor32OrigBarrier(uint32_t __theMask
, volatile uint32_t *__theValue
)
1007 return (int32_t)(OSATOMIC_STD(atomic_fetch_xor_explicit
)(
1008 (volatile _OSAtomic_uint32_t
*)__theValue
, __theMask
,
1009 OSATOMIC_STD(memory_order_seq_cst
)));
1014 OSAtomicCompareAndSwap32(int32_t __oldValue
, int32_t __newValue
,
1015 volatile int32_t *__theValue
)
1017 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1018 (volatile _OSAtomic_int32_t
*)__theValue
, &__oldValue
, __newValue
,
1019 OSATOMIC_STD(memory_order_relaxed
),
1020 OSATOMIC_STD(memory_order_relaxed
)));
1025 OSAtomicCompareAndSwap32Barrier(int32_t __oldValue
, int32_t __newValue
,
1026 volatile int32_t *__theValue
)
1028 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1029 (volatile _OSAtomic_int32_t
*)__theValue
, &__oldValue
, __newValue
,
1030 OSATOMIC_STD(memory_order_seq_cst
),
1031 OSATOMIC_STD(memory_order_relaxed
)));
1036 OSAtomicCompareAndSwapPtr(void *__oldValue
, void *__newValue
,
1037 void * volatile *__theValue
)
1039 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1040 (volatile _OSAtomic_void_ptr_t
*)__theValue
, &__oldValue
, __newValue
,
1041 OSATOMIC_STD(memory_order_relaxed
),
1042 OSATOMIC_STD(memory_order_relaxed
)));
1047 OSAtomicCompareAndSwapPtrBarrier(void *__oldValue
, void *__newValue
,
1048 void * volatile *__theValue
)
1050 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1051 (volatile _OSAtomic_void_ptr_t
*)__theValue
, &__oldValue
, __newValue
,
1052 OSATOMIC_STD(memory_order_seq_cst
),
1053 OSATOMIC_STD(memory_order_relaxed
)));
1058 OSAtomicCompareAndSwapInt(int __oldValue
, int __newValue
,
1059 volatile int *__theValue
)
1061 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1062 (volatile OSATOMIC_STD(atomic_int
)*)__theValue
, &__oldValue
,
1063 __newValue
, OSATOMIC_STD(memory_order_relaxed
),
1064 OSATOMIC_STD(memory_order_relaxed
)));
1069 OSAtomicCompareAndSwapIntBarrier(int __oldValue
, int __newValue
,
1070 volatile int *__theValue
)
1072 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1073 (volatile OSATOMIC_STD(atomic_int
)*)__theValue
, &__oldValue
,
1074 __newValue
, OSATOMIC_STD(memory_order_seq_cst
),
1075 OSATOMIC_STD(memory_order_relaxed
)));
1080 OSAtomicCompareAndSwapLong(long __oldValue
, long __newValue
,
1081 volatile long *__theValue
)
1083 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1084 (volatile OSATOMIC_STD(atomic_long
)*)__theValue
, &__oldValue
,
1085 __newValue
, OSATOMIC_STD(memory_order_relaxed
),
1086 OSATOMIC_STD(memory_order_relaxed
)));
1091 OSAtomicCompareAndSwapLongBarrier(long __oldValue
, long __newValue
,
1092 volatile long *__theValue
)
1094 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1095 (volatile OSATOMIC_STD(atomic_long
)*)__theValue
, &__oldValue
,
1096 __newValue
, OSATOMIC_STD(memory_order_seq_cst
),
1097 OSATOMIC_STD(memory_order_relaxed
)));
1102 OSAtomicCompareAndSwap64(int64_t __oldValue
, int64_t __newValue
,
1103 volatile OSAtomic_int64_aligned64_t
*__theValue
)
1105 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1106 (volatile _OSAtomic_int64_t
*)__theValue
, &__oldValue
, __newValue
,
1107 OSATOMIC_STD(memory_order_relaxed
),
1108 OSATOMIC_STD(memory_order_relaxed
)));
1113 OSAtomicCompareAndSwap64Barrier(int64_t __oldValue
, int64_t __newValue
,
1114 volatile OSAtomic_int64_aligned64_t
*__theValue
)
1116 return (OSATOMIC_STD(atomic_compare_exchange_strong_explicit
)(
1117 (volatile _OSAtomic_int64_t
*)__theValue
, &__oldValue
, __newValue
,
1118 OSATOMIC_STD(memory_order_seq_cst
),
1119 OSATOMIC_STD(memory_order_relaxed
)));
1124 OSAtomicTestAndSet(uint32_t __n
, volatile void *__theAddress
)
1126 uintptr_t a
= (uintptr_t)__theAddress
+ (__n
>> 3);
1127 uint8_t v
= (0x80u
>> (__n
& 7));
1128 return (OSATOMIC_STD(atomic_fetch_or_explicit
)((_OSAtomic_uint8_t
*)a
, v
,
1129 OSATOMIC_STD(memory_order_relaxed
)) & v
);
1134 OSAtomicTestAndSetBarrier(uint32_t __n
, volatile void *__theAddress
)
1136 uintptr_t a
= (uintptr_t)__theAddress
+ (__n
>> 3);
1137 uint8_t v
= (0x80u
>> (__n
& 7));
1138 return (OSATOMIC_STD(atomic_fetch_or_explicit
)((_OSAtomic_uint8_t
*)a
, v
,
1139 OSATOMIC_STD(memory_order_seq_cst
)) & v
);
1144 OSAtomicTestAndClear(uint32_t __n
, volatile void *__theAddress
)
1146 uintptr_t a
= (uintptr_t)__theAddress
+ (__n
>> 3);
1147 uint8_t v
= (0x80u
>> (__n
& 7));
1148 return (OSATOMIC_STD(atomic_fetch_and_explicit
)((_OSAtomic_uint8_t
*)a
,
1149 (uint8_t)~v
, OSATOMIC_STD(memory_order_relaxed
)) & v
);
1154 OSAtomicTestAndClearBarrier(uint32_t __n
, volatile void *__theAddress
)
1156 uintptr_t a
= (uintptr_t)__theAddress
+ (__n
>> 3);
1157 uint8_t v
= (0x80u
>> (__n
& 7));
1158 return (OSATOMIC_STD(atomic_fetch_and_explicit
)((_OSAtomic_uint8_t
*)a
,
1159 (uint8_t)~v
, OSATOMIC_STD(memory_order_seq_cst
)) & v
);
1164 OSMemoryBarrier(void)
1166 OSATOMIC_STD(atomic_thread_fence
)(OSATOMIC_STD(memory_order_seq_cst
));
1169 #undef OSATOMIC_INLINE
1176 #endif // defined(OSATOMIC_USE_INLINED) && OSATOMIC_USE_INLINED
1178 #if TARGET_OS_OSX || TARGET_OS_DRIVERKIT
1182 /*! @group Lockless atomic fifo enqueue and dequeue
1183 * These routines manipulate singly-linked FIFO lists.
1185 * This API is deprecated and no longer recommended
1188 /*! @abstract The data structure for a fifo queue head.
1190 You should always initialize a fifo queue head structure with the
1191 initialization vector {@link OS_ATOMIC_FIFO_QUEUE_INIT} before use.
1193 #if defined(__LP64__)
1195 typedef volatile struct {
1199 } __attribute__ ((aligned (16))) OSFifoQueueHead
;
1203 typedef volatile struct {
1210 /*! @abstract The initialization vector for a fifo queue head. */
1211 #define OS_ATOMIC_FIFO_QUEUE_INIT { NULL, NULL, 0 }
1213 /*! @abstract Enqueue an element onto a list.
1215 Memory barriers are incorporated as needed to permit thread-safe access
1216 to the queue element.
1218 The list on which you want to enqueue the element.
1222 The "offset" parameter is the offset (in bytes) of the link field
1223 from the beginning of the data structure being queued (<code>__new</code>).
1224 The link field should be a pointer type.
1225 The <code>__offset</code> value needs to be same for all enqueuing and
1226 dequeuing operations on the same list, even if different structure types
1227 are enqueued on that list. The use of <code>offsetset()</code>, defined in
1228 <code>stddef.h</code> is the common way to specify the <code>__offset</code>
1232 This API is deprecated and no longer recommended
1234 __API_DEPRECATED("No longer supported", macos(10.7, 10.16))
1235 void OSAtomicFifoEnqueue( OSFifoQueueHead
*__list
, void *__new
, size_t __offset
);
1237 /*! @abstract Dequeue an element from a list.
1239 Memory barriers are incorporated as needed to permit thread-safe access
1240 to the queue element.
1242 The list from which you want to dequeue an element.
1244 The "offset" parameter is the offset (in bytes) of the link field
1245 from the beginning of the data structure being dequeued (<code>__new</code>).
1246 The link field should be a pointer type.
1247 The <code>__offset</code> value needs to be same for all enqueuing and
1248 dequeuing operations on the same list, even if different structure types
1249 are enqueued on that list. The use of <code>offsetset()</code>, defined in
1250 <code>stddef.h</code> is the common way to specify the <code>__offset</code>
1253 Returns the oldest enqueued element, or <code>NULL</code> if the
1257 This API is deprecated and no longer recommended
1259 __API_DEPRECATED("No longer supported", macos(10.7, 10.16))
1260 void* OSAtomicFifoDequeue( OSFifoQueueHead
*__list
, size_t __offset
);
1264 #endif /* TARGET_OS_OSX || TARGET_OS_DRIVERKIT */
1266 #endif /* _OSATOMIC_DEPRECATED_H_ */