···1919# message(FATAL_ERROR "BITS is not specified (32/64)")
2020#endif (NOT BITS)
21212222-SET(IGNORED_WARNINGS "-Wno-nullability-completeness")
2222+SET(IGNORED_WARNINGS "-Wno-nullability-completeness -Wno-deprecated-declarations")
23232424if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang" AND NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS "3.9")
2525 SET(IGNORED_WARNINGS "${IGNORED_WARNINGS} -Wno-expansion-to-defined")
-648
kernel-include/libkern/OSAtomic.h
···11-/*
22- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
33- *
44- * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55- *
66- * This file contains Original Code and/or Modifications of Original Code
77- * as defined in and that are subject to the Apple Public Source License
88- * Version 2.0 (the 'License'). You may not use this file except in
99- * compliance with the License. The rights granted to you under the License
1010- * may not be used to create, or enable the creation or redistribution of,
1111- * unlawful or unlicensed copies of an Apple operating system, or to
1212- * circumvent, violate, or enable the circumvention or violation of, any
1313- * terms of an Apple operating system software license agreement.
1414- *
1515- * Please obtain a copy of the License at
1616- * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717- *
1818- * The Original Code and all software distributed under the License are
1919- * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020- * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222- * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323- * Please see the License for the specific language governing rights and
2424- * limitations under the License.
2525- *
2626- * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727- */
2828-/*
2929- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3030- *
3131- * HISTORY
3232- *
3333- */
3434-3535-#ifndef _OS_OSATOMIC_H
3636-#define _OS_OSATOMIC_H
3737-3838-#include <libkern/OSBase.h>
3939-4040-#if defined(__cplusplus)
4141-extern "C" {
4242-#endif
4343-4444-#ifdef XNU_KERNEL_PRIVATE
4545-/*
4646- * The macro SAFE_CAST_PTR() casts one type of pointer to another type, making sure
4747- * the data the pointer is referencing is the same size. If it is not, it will cause
4848- * a division by zero compiler warning. This is to work around "SInt32" being defined
4949- * as "long" on ILP32 and as "int" on LP64, which would require an explicit cast to
5050- * "SInt32*" when for instance passing an "int*" to OSAddAtomic() - which masks size
5151- * mismatches.
5252- * -- var is used, but sizeof does not evaluate the
5353- * argument, i.e. we're safe against "++" etc. in var --
5454- */
5555-#define __SAFE_CAST_PTR(type, var) (((type)(var))+(0/(sizeof(*var) == sizeof(*(type)0) ? 1 : 0)))
5656-#else
5757-#define __SAFE_CAST_PTR(type, var) ((type)(var))
5858-#endif
5959-6060-/*!
6161- * @header
6262- *
6363- * @abstract
6464- * This header declares the OSAtomic group of functions for atomic
6565- * reading and updating of values.
6666- */
6767-6868-#if defined(__i386__) || defined(__x86_64__) || defined(__arm__)
6969-7070-/*!
7171- * @function OSCompareAndSwap64
7272- *
7373- * @abstract
7474- * 64-bit compare and swap operation.
7575- *
7676- * @discussion
7777- * See OSCompareAndSwap.
7878- */
7979-extern Boolean OSCompareAndSwap64(
8080- UInt64 oldValue,
8181- UInt64 newValue,
8282- volatile UInt64 * address);
8383-#define OSCompareAndSwap64(a, b, c) \
8484- (OSCompareAndSwap64(a, b, __SAFE_CAST_PTR(volatile UInt64*,c)))
8585-8686-#endif /* defined(__i386__) || defined(__x86_64__) */
8787-8888-/*!
8989- * @function OSAddAtomic64
9090- *
9191- * @abstract
9292- * 64-bit atomic add operation.
9393- *
9494- * @discussion
9595- * See OSAddAtomic.
9696- */
9797-extern SInt64 OSAddAtomic64(
9898- SInt64 theAmount,
9999- volatile SInt64 * address);
100100-#define OSAddAtomic64(a, b) \
101101- (OSAddAtomic64(a, __SAFE_CAST_PTR(volatile SInt64*,b)))
102102-103103-/*!
104104- * @function OSIncrementAtomic64
105105- *
106106- * @abstract
107107- * 64-bit increment.
108108- *
109109- * @discussion
110110- * See OSIncrementAtomic.
111111-*/
112112-inline static SInt64 OSIncrementAtomic64(volatile SInt64 * address)
113113-{
114114- return OSAddAtomic64(1LL, address);
115115-}
116116-117117-/*!
118118- * @function OSDecrementAtomic64
119119- *
120120- * @abstract
121121- * 64-bit decrement.
122122- *
123123- * @discussion
124124- * See OSDecrementAtomic.
125125-*/
126126-inline static SInt64 OSDecrementAtomic64(volatile SInt64 * address)
127127-{
128128- return OSAddAtomic64(-1LL, address);
129129-}
130130-131131-#if XNU_KERNEL_PRIVATE
132132-/* Not to be included in headerdoc.
133133- *
134134- * @function OSAddAtomicLong
135135- *
136136- * @abstract
137137- * 32/64-bit atomic add operation, depending on sizeof(long).
138138- *
139139- * @discussion
140140- * See OSAddAtomic.
141141- */
142142-extern long OSAddAtomicLong(
143143- long theAmount,
144144- volatile long * address);
145145-#define OSAddAtomicLong(a, b) \
146146- (OSAddAtomicLong(a, __SAFE_CAST_PTR(volatile long*,b)))
147147-148148-/* Not to be included in headerdoc.
149149- *
150150- * @function OSIncrementAtomicLong
151151- *
152152- * @abstract
153153- * 32/64-bit increment, depending on sizeof(long)
154154- *
155155- * @discussion
156156- * See OSIncrementAtomic.
157157-*/
158158-inline static long OSIncrementAtomicLong(volatile long * address)
159159-{
160160- return OSAddAtomicLong(1L, address);
161161-}
162162-163163-/* Not to be included in headerdoc.
164164- *
165165- * @function OSDecrementAtomicLong
166166- *
167167- * @abstract
168168- * 32/64-bit decrement, depending on sizeof(long)
169169- *@discussion See OSDecrementAtomic.
170170- */
171171-inline static long OSDecrementAtomicLong(volatile long * address)
172172-{
173173- return OSAddAtomicLong(-1L, address);
174174-}
175175-#endif /* XNU_KERNEL_PRIVATE */
176176-177177-/*!
178178- * @function OSCompareAndSwap
179179- *
180180- * @abstract
181181- * Compare and swap operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
182182- *
183183- * @discussion
184184- * The OSCompareAndSwap function compares the value at the specified address with oldVal. The value of newValue is written to the address only if oldValue and the value at the address are equal. OSCompareAndSwap returns true if newValue is written to the address; otherwise, it returns false.
185185- *
186186- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
187187- *
188188- * @param oldValue The value to compare at address.
189189- * @param newValue The value to write to address if oldValue compares true.
190190- * @param address The 4-byte aligned address of the data to update atomically.
191191- * @result true if newValue was written to the address.
192192- */
193193-extern Boolean OSCompareAndSwap(
194194- UInt32 oldValue,
195195- UInt32 newValue,
196196- volatile UInt32 * address);
197197-#define OSCompareAndSwap(a, b, c) \
198198- (OSCompareAndSwap(a, b, __SAFE_CAST_PTR(volatile UInt32*,c)))
199199-200200-/*!
201201- * @function OSCompareAndSwapPtr
202202- *
203203- * @abstract
204204- * Compare and swap operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
205205- *
206206- * @discussion
207207- * The OSCompareAndSwapPtr function compares the pointer-sized value at the specified address with oldVal. The value of newValue is written to the address only if oldValue and the value at the address are equal. OSCompareAndSwapPtr returns true if newValue is written to the address; otherwise, it returns false.
208208- *
209209- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
210210- * @param oldValue The pointer value to compare at address.
211211- * @param newValue The pointer value to write to address if oldValue compares true.
212212- * @param address The pointer-size aligned address of the data to update atomically.
213213- * @result true if newValue was written to the address.
214214- */
215215-extern Boolean OSCompareAndSwapPtr(
216216- void * oldValue,
217217- void * newValue,
218218- void * volatile * address);
219219-#define OSCompareAndSwapPtr(a, b, c) \
220220- (OSCompareAndSwapPtr(a, b, __SAFE_CAST_PTR(void * volatile *,c)))
221221-222222-/*!
223223- * @function OSAddAtomic
224224- *
225225- * @abstract
226226- * 32-bit add operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
227227- *
228228- * @discussion
229229- * The OSAddAtomic function adds the specified amount to the value at the specified address and returns the original value.
230230- *
231231- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
232232- * @param amount The amount to add.
233233- * @param address The 4-byte aligned address of the value to update atomically.
234234- * @result The value before the addition
235235- */
236236-extern SInt32 OSAddAtomic(
237237- SInt32 amount,
238238- volatile SInt32 * address);
239239-#define OSAddAtomic(a, b) \
240240- (OSAddAtomic(a, __SAFE_CAST_PTR(volatile SInt32*,b)))
241241-242242-/*!
243243- * @function OSAddAtomic16
244244- *
245245- * @abstract
246246- * 16-bit add operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
247247- *
248248- * @discussion
249249- * The OSAddAtomic16 function adds the specified amount to the value at the specified address and returns the original value.
250250- *
251251- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
252252- * @param amount The amount to add.
253253- * @param address The 2-byte aligned address of the value to update atomically.
254254- * @result The value before the addition
255255- */
256256-extern SInt16 OSAddAtomic16(
257257- SInt32 amount,
258258- volatile SInt16 * address);
259259-260260-/*!
261261- * @function OSAddAtomic8
262262- *
263263- * @abstract
264264- * 8-bit add operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
265265- *
266266- * @discussion
267267- * The OSAddAtomic8 function adds the specified amount to the value at the specified address and returns the original value.
268268- *
269269- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
270270- * @param amount The amount to add.
271271- * @param address The address of the value to update atomically.
272272- * @result The value before the addition.
273273- */
274274-extern SInt8 OSAddAtomic8(
275275- SInt32 amount,
276276- volatile SInt8 * address);
277277-278278-/*!
279279- * @function OSIncrementAtomic
280280- *
281281- * @abstract
282282- * 32-bit increment operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
283283- *
284284- * @discussion
285285- * The OSIncrementAtomic function increments the value at the specified address by one and returns the original value.
286286- *
287287- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device.
288288- * @param address The 4-byte aligned address of the value to update atomically.
289289- * @result The value before the increment.
290290- */
291291-extern SInt32 OSIncrementAtomic(volatile SInt32 * address);
292292-#define OSIncrementAtomic(a) \
293293- (OSIncrementAtomic(__SAFE_CAST_PTR(volatile SInt32*,a)))
294294-295295-/*!
296296- * @function OSIncrementAtomic16
297297- *
298298- * @abstract
299299- * 16-bit increment operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
300300- *
301301- * @discussion
302302- * The OSIncrementAtomic16 function increments the value at the specified address by one and returns the original value.
303303- *
304304- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
305305- * @param address The 2-byte aligned address of the value to update atomically.
306306- * @result The value before the increment.
307307- */
308308-extern SInt16 OSIncrementAtomic16(volatile SInt16 * address);
309309-310310-/*!
311311- * @function OSIncrementAtomic8
312312- *
313313- * @abstract
314314- * 8-bit increment operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
315315- *
316316- * @discussion
317317- * The OSIncrementAtomic8 function increments the value at the specified address by one and returns the original value.
318318- *
319319- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
320320- * @param address The address of the value to update atomically.
321321- * @result The value before the increment.
322322- */
323323-extern SInt8 OSIncrementAtomic8(volatile SInt8 * address);
324324-325325-/*!
326326- * @function OSDecrementAtomic
327327- *
328328- * @abstract
329329- * 32-bit decrement operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
330330- *
331331- * @discussion
332332- * The OSDecrementAtomic function decrements the value at the specified address by one and returns the original value.
333333- *
334334- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
335335- * @param address The 4-byte aligned address of the value to update atomically.
336336- * @result The value before the decrement.
337337- */
338338-extern SInt32 OSDecrementAtomic(volatile SInt32 * address);
339339-#define OSDecrementAtomic(a) \
340340- (OSDecrementAtomic(__SAFE_CAST_PTR(volatile SInt32*,a)))
341341-342342-/*!
343343- * @function OSDecrementAtomic16
344344- *
345345- * @abstract
346346- * 16-bit decrement operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
347347- *
348348- * @discussion
349349- * The OSDecrementAtomic16 function decrements the value at the specified address by one and returns the original value.
350350- *
351351- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
352352- * @param address The 2-byte aligned address of the value to update atomically.
353353- * @result The value before the decrement.
354354- */
355355-extern SInt16 OSDecrementAtomic16(volatile SInt16 * address);
356356-357357-/*!
358358- * @function OSDecrementAtomic8
359359- *
360360- * @abstract
361361- * 8-bit decrement operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
362362- *
363363- * @discussion
364364- * The OSDecrementAtomic8 function decrements the value at the specified address by one and returns the original value.
365365- *
366366- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
367367- * @param address The address of the value to update atomically.
368368- * @result The value before the decrement.
369369- */
370370-extern SInt8 OSDecrementAtomic8(volatile SInt8 * address);
371371-372372-/*!
373373- * @function OSBitAndAtomic
374374- *
375375- * @abstract
376376- * 32-bit logical and operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
377377- *
378378- * @discussion
379379- * The OSBitAndAtomic function logically ands the bits of the specified mask into the value at the specified address and returns the original value.
380380- *
381381- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
382382- * @param mask The mask to logically and with the value.
383383- * @param address The 4-byte aligned address of the value to update atomically.
384384- * @result The value before the bitwise operation
385385- */
386386-extern UInt32 OSBitAndAtomic(
387387- UInt32 mask,
388388- volatile UInt32 * address);
389389-#define OSBitAndAtomic(a, b) \
390390- (OSBitAndAtomic(a, __SAFE_CAST_PTR(volatile UInt32*,b)))
391391-392392-/*!
393393- * @function OSBitAndAtomic16
394394- *
395395- * @abstract
396396- * 16-bit logical and operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
397397- *
398398- * @discussion
399399- * The OSBitAndAtomic16 function logically ands the bits of the specified mask into the value at the specified address and returns the original value.
400400- *
401401- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
402402- * @param mask The mask to logically and with the value.
403403- * @param address The 2-byte aligned address of the value to update atomically.
404404- * @result The value before the bitwise operation.
405405- */
406406-extern UInt16 OSBitAndAtomic16(
407407- UInt32 mask,
408408- volatile UInt16 * address);
409409-410410-/*!
411411- * @function OSBitAndAtomic8
412412- *
413413- * @abstract
414414- * 8-bit logical and operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
415415- *
416416- * @discussion
417417- * The OSBitAndAtomic8 function logically ands the bits of the specified mask into the value at the specified address and returns the original value.
418418- *
419419- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
420420- * @param mask The mask to logically and with the value.
421421- * @param address The address of the value to update atomically.
422422- * @result The value before the bitwise operation.
423423- */
424424-extern UInt8 OSBitAndAtomic8(
425425- UInt32 mask,
426426- volatile UInt8 * address);
427427-428428-/*!
429429- * @function OSBitOrAtomic
430430- *
431431- * @abstract
432432- * 32-bit logical or operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
433433- *
434434- * @discussion
435435- * The OSBitOrAtomic function logically ors the bits of the specified mask into the value at the specified address and returns the original value.
436436- *
437437- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
438438- * @param mask The mask to logically or with the value.
439439- * @param address The 4-byte aligned address of the value to update atomically.
440440- * @result The value before the bitwise operation.
441441- */
442442-extern UInt32 OSBitOrAtomic(
443443- UInt32 mask,
444444- volatile UInt32 * address);
445445-#define OSBitOrAtomic(a, b) \
446446- (OSBitOrAtomic(a, __SAFE_CAST_PTR(volatile UInt32*,b)))
447447-448448-/*!
449449- * @function OSBitOrAtomic16
450450- *
451451- * @abstract
452452- * 16-bit logical or operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
453453- *
454454- * @discussion
455455- * The OSBitOrAtomic16 function logically ors the bits of the specified mask into the value at the specified address and returns the original value.
456456- *
457457- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
458458- * @param mask The mask to logically or with the value.
459459- * @param address The 2-byte aligned address of the value to update atomically.
460460- * @result The value before the bitwise operation.
461461- */
462462-extern UInt16 OSBitOrAtomic16(
463463- UInt32 mask,
464464- volatile UInt16 * address);
465465-466466-/*!
467467- * @function OSBitOrAtomic8
468468- *
469469- * @abstract
470470- * 8-bit logical or operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
471471- *
472472- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
473473- *
474474- * @discussion
475475- * The OSBitOrAtomic8 function logically ors the bits of the specified mask into the value at the specified address and returns the original value.
476476- * @param mask The mask to logically or with the value.
477477- * @param address The address of the value to update atomically.
478478- * @result The value before the bitwise operation.
479479- */
480480-extern UInt8 OSBitOrAtomic8(
481481- UInt32 mask,
482482- volatile UInt8 * address);
483483-484484-/*!
485485- * @function OSBitXorAtomic
486486- *
487487- * @abstract
488488- * 32-bit logical xor operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
489489- *
490490- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
491491- *
492492- * @discussion
493493- * The OSBitXorAtomic function logically xors the bits of the specified mask into the value at the specified address and returns the original value.
494494- * @param mask The mask to logically or with the value.
495495- * @param address The 4-byte aligned address of the value to update atomically.
496496- * @result The value before the bitwise operation.
497497- */
498498-extern UInt32 OSBitXorAtomic(
499499- UInt32 mask,
500500- volatile UInt32 * address);
501501-#define OSBitXorAtomic(a, b) \
502502- (OSBitXorAtomic(a, __SAFE_CAST_PTR(volatile UInt32*,b)))
503503-504504-/*!
505505- * @function OSBitXorAtomic16
506506- *
507507- * @abstract
508508- * 16-bit logical xor operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
509509- *
510510- * @discussion
511511- * The OSBitXorAtomic16 function logically xors the bits of the specified mask into the value at the specified address and returns the original value.
512512- *
513513- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
514514- * @param mask The mask to logically or with the value.
515515- * @param address The 2-byte aligned address of the value to update atomically.
516516- * @result The value before the bitwise operation.
517517- */
518518-extern UInt16 OSBitXorAtomic16(
519519- UInt32 mask,
520520- volatile UInt16 * address);
521521-522522-/*!
523523- * @function OSBitXorAtomic8
524524- *
525525- * @abstract
526526- * 8-bit logical xor operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
527527- *
528528- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
529529- *
530530- * @discussion
531531- * The OSBitXorAtomic8 function logically xors the bits of the specified mask into the value at the specified address and returns the original value.
532532- * @param mask The mask to logically or with the value.
533533- * @param address The address of the value to update atomically.
534534- * @result The value before the bitwise operation.
535535- */
536536-extern UInt8 OSBitXorAtomic8(
537537- UInt32 mask,
538538- volatile UInt8 * address);
539539-540540-/*!
541541- * @function OSTestAndSet
542542- *
543543- * @abstract
544544- * Bit test and set operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
545545- *
546546- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
547547- *
548548- * @discussion
549549- * The OSTestAndSet function sets a single bit in a byte at a specified address. It returns true if the bit was already set, false otherwise.
550550- * @param bit The bit number in the range 0 through 7.
551551- * @param startAddress The address of the byte to update atomically.
552552- * @result true if the bit was already set, false otherwise.
553553- */
554554-extern Boolean OSTestAndSet(
555555- UInt32 bit,
556556- volatile UInt8 * startAddress);
557557-558558-/*!
559559- * @function OSTestAndClear
560560- *
561561- * @abstract
562562- * Bit test and clear operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform.
563563- *
564564- * @discussion
565565- * The OSTestAndClear function clears a single bit in a byte at a specified address. It returns true if the bit was already clear, false otherwise.
566566- *
567567- * This function guarantees atomicity only with main system memory. It is specifically unsuitable for use on noncacheable memory such as that in devices; this function cannot guarantee atomicity, for example, on memory mapped from a PCI device. Additionally, this function incorporates a memory barrier on systems with weakly-ordered memory architectures.
568568- * @param bit The bit number in the range 0 through 7.
569569- * @param startAddress The address of the byte to update atomically.
570570- * @result true if the bit was already clear, false otherwise.
571571- */
572572-extern Boolean OSTestAndClear(
573573- UInt32 bit,
574574- volatile UInt8 * startAddress);
575575-576576-/*!
577577- * @defined OS_SPINLOCK_INIT
578578- *
579579- * @abstract
580580- * The default value for an OSSpinLock.
581581- *
582582- * @discussion
583583- * The convention is that unlocked is zero, locked is nonzero.
584584- */
585585-#define OS_SPINLOCK_INIT 0
586586-587587-/*!
588588- * @typedef OSSpinLock
589589- *
590590- * @abstract
591591- * Data type for a spinlock.
592592- *
593593- * @discussion
594594- * You should always initialize a spinlock to OS_SPINLOCK_INIT before using it.
595595- */
596596-typedef SInt32 OSSpinLock;
597597-598598-#ifdef PRIVATE
599599-/*!
600600- * @function OSSpinLockTry
601601- *
602602- * @abstract
603603- * Locks a spinlock if it would not block.
604604- *
605605- * @discussion
606606- * Multiprocessor locks used within the shared memory area between the kernel and event system. These must work in both user and kernel mode.
607607- *
608608- * @result
609609- * Returns false if the lock was already held by another thread, true if it took the lock successfully.
610610- */
611611-extern Boolean OSSpinLockTry(volatile OSSpinLock * lock);
612612-613613-/*!
614614- * @function OSSpinLockUnlock
615615- *
616616- * @abstract
617617- * Unlocks a spinlock.
618618- *
619619- * @discussion
620620- * Unlocks a spinlock.
621621- */
622622-extern void OSSpinLockUnlock(volatile OSSpinLock * lock);
623623-#endif /* PRIVATE */
624624-625625-/*!
626626- * @function OSSynchronizeIO
627627- *
628628- * @abstract
629629- * The OSSynchronizeIO routine ensures orderly load and store operations to noncached memory mapped I/O devices.
630630- *
631631- * @discussion
632632- * The OSSynchronizeIO routine ensures orderly load and store operations to noncached memory mapped I/O devices. It executes the eieio instruction on PowerPC processors.
633633- */
634634-static __inline__ void OSSynchronizeIO(void)
635635-{
636636-}
637637-#if defined(XNU_KERNEL_PRIVATE)
638638-#if defined(__i386__) || defined(__x86_64__)
639639-static inline void OSMemoryBarrier(void) {
640640- __asm__ volatile("mfence" ::: "memory");
641641-}
642642-#endif
643643-#endif /*XNU_KERNEL_PRIVATE */
644644-#if defined(__cplusplus)
645645-}
646646-#endif
647647-648648-#endif /* ! _OS_OSATOMIC_H */