#include <libkern/OSAtomic.h>

libkern/OSAtomic.h Kernel.framework

@header @abstract This header declares the OSAtomic group of functions for atomic reading and updating of values.
includes: libkern/OSBase.h, Kernel/string.h
27 functions · 10 macros · 1 typedef

functionOSCompareAndSwap64

extern Boolean OSCompareAndSwap64(
	UInt64 oldValue,
	UInt64 newValue,
	volatile UInt64 * address
)
@function OSCompareAndSwap64 @abstract 64-bit compare and swap operation. @discussion See OSCompareAndSwap.

macroOSCompareAndSwap64

#define OSCompareAndSwap64(a, b, c) (OSCompareAndSwap64(a, b, __SAFE_CAST_PTR(volatile UInt64*,c)))

functionOSAddAtomic64

extern SInt64 OSAddAtomic64(SInt64 theAmount, volatile SInt64 * address)
@function OSAddAtomic64 @abstract 64-bit atomic add operation. @discussion See OSAddAtomic.

macroOSAddAtomic64

#define OSAddAtomic64(a, b) (OSAddAtomic64(a, __SAFE_CAST_PTR(volatile SInt64*,b)))

functionOSIncrementAtomic64

inline static SInt64 OSIncrementAtomic64(volatile SInt64 * address)
@function OSIncrementAtomic64 @abstract 64-bit increment. @discussion See OSIncrementAtomic.

functionOSDecrementAtomic64

inline static SInt64 OSDecrementAtomic64(volatile SInt64 * address)
@function OSDecrementAtomic64 @abstract 64-bit decrement. @discussion See OSDecrementAtomic.

functionOSCompareAndSwap

extern Boolean OSCompareAndSwap(
	UInt32 oldValue,
	UInt32 newValue,
	volatile UInt32 * address
)
@function OSCompareAndSwap @abstract Compare and swap operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion 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. 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. @param oldValue The value to compare at address. @param newValue The value to write to address if oldValue compares true. @param address The 4-byte aligned address of the data to update atomically. @result true if newValue was written to the address.

macroOSCompareAndSwap

#define OSCompareAndSwap(a, b, c) (OSCompareAndSwap(a, b, __SAFE_CAST_PTR(volatile UInt32*,c)))

functionOSCompareAndSwapPtr

extern Boolean OSCompareAndSwapPtr(
	void * oldValue,
	void * newValue,
	void * volatile * address
)
@function OSCompareAndSwapPtr @abstract Compare and swap operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion 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. 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. @param oldValue The pointer value to compare at address. @param newValue The pointer value to write to address if oldValue compares true. @param address The pointer-size aligned address of the data to update atomically. @result true if newValue was written to the address.

macroOSCompareAndSwapPtr

#define OSCompareAndSwapPtr(a, b, c) (OSCompareAndSwapPtr(a, b, __SAFE_CAST_PTR(void * volatile *,c)))

functionOSAddAtomic

extern SInt32 OSAddAtomic(SInt32 amount, volatile SInt32 * address)
@function OSAddAtomic @abstract 32-bit add operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSAddAtomic function adds the specified amount to the value at the specified address and returns the original value. 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. Previous incarnations of this function incorporated a memory barrier on systems with weakly-ordered memory architectures, but current versions contain no barriers. @param amount The amount to add. @param address The 4-byte aligned address of the value to update atomically. @result The value before the addition

macroOSAddAtomic

#define OSAddAtomic(a, b) (OSAddAtomic(a, __SAFE_CAST_PTR(volatile SInt32*,b)))

functionOSAddAtomic16

extern SInt16 OSAddAtomic16(SInt32 amount, volatile SInt16 * address)
@function OSAddAtomic16 @abstract 16-bit add operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSAddAtomic16 function adds the specified amount to the value at the specified address and returns the original value. 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. Previous incarnations of this function incorporated a memory barrier on systems with weakly-ordered memory architectures, but current versions contain no barriers. @param address The 2-byte aligned address of the value to update atomically. @result The value before the addition

functionOSAddAtomic8

extern SInt8 OSAddAtomic8(SInt32 amount, volatile SInt8 * address)
@function OSAddAtomic8 @abstract 8-bit add operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSAddAtomic8 function adds the specified amount to the value at the specified address and returns the original value. 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. Previous incarnations of this function incorporated a memory barrier on systems with weakly-ordered memory architectures, but current versions contain no barriers. @param amount The amount to add. @param address The address of the value to update atomically. @result The value before the addition.

functionOSIncrementAtomic

extern SInt32 OSIncrementAtomic(volatile SInt32 * address)
@function OSIncrementAtomic @abstract 32-bit increment operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSIncrementAtomic function increments the value at the specified address by one and returns the original value. 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. @param address The 4-byte aligned address of the value to update atomically. @result The value before the increment.

macroOSIncrementAtomic

#define OSIncrementAtomic(a) (OSIncrementAtomic(__SAFE_CAST_PTR(volatile SInt32*,a)))

functionOSIncrementAtomic16

extern SInt16 OSIncrementAtomic16(volatile SInt16 * address)
@function OSIncrementAtomic16 @abstract 16-bit increment operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSIncrementAtomic16 function increments the value at the specified address by one and returns the original value. 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. Previous incarnations of this function incorporated a memory barrier on systems with weakly-ordered memory architectures, but current versions contain no barriers. @param address The 2-byte aligned address of the value to update atomically. @result The value before the increment.

functionOSIncrementAtomic8

extern SInt8 OSIncrementAtomic8(volatile SInt8 * address)
@function OSIncrementAtomic8 @abstract 8-bit increment operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSIncrementAtomic8 function increments the value at the specified address by one and returns the original value. 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. Previous incarnations of this function incorporated a memory barrier on systems with weakly-ordered memory architectures, but current versions contain no barriers. @param address The address of the value to update atomically. @result The value before the increment.

functionOSDecrementAtomic

extern SInt32 OSDecrementAtomic(volatile SInt32 * address)
@function OSDecrementAtomic @abstract 32-bit decrement operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSDecrementAtomic function decrements the value at the specified address by one and returns the original value. 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. Previous incarnations of this function incorporated a memory barrier on systems with weakly-ordered memory architectures, but current versions contain no barriers. @param address The 4-byte aligned address of the value to update atomically. @result The value before the decrement.

macroOSDecrementAtomic

#define OSDecrementAtomic(a) (OSDecrementAtomic(__SAFE_CAST_PTR(volatile SInt32*,a)))

functionOSDecrementAtomic16

extern SInt16 OSDecrementAtomic16(volatile SInt16 * address)
@function OSDecrementAtomic16 @abstract 16-bit decrement operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSDecrementAtomic16 function decrements the value at the specified address by one and returns the original value. 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. Previous incarnations of this function incorporated a memory barrier on systems with weakly-ordered memory architectures, but current versions contain no barriers. @param address The 2-byte aligned address of the value to update atomically. @result The value before the decrement.

functionOSDecrementAtomic8

extern SInt8 OSDecrementAtomic8(volatile SInt8 * address)
@function OSDecrementAtomic8 @abstract 8-bit decrement operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSDecrementAtomic8 function decrements the value at the specified address by one and returns the original value. 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. Previous incarnations of this function incorporated a memory barrier on systems with weakly-ordered memory architectures, but current versions contain no barriers. @param address The address of the value to update atomically. @result The value before the decrement.

functionOSBitAndAtomic

extern UInt32 OSBitAndAtomic(UInt32 mask, volatile UInt32 * address)
@function OSBitAndAtomic @abstract 32-bit logical and operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSBitAndAtomic function logically ands the bits of the specified mask into the value at the specified address and returns the original value. 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. Previous incarnations of this function incorporated a memory barrier on systems with weakly-ordered memory architectures, but current versions contain no barriers.. @param mask The mask to logically and with the value. @param address The 4-byte aligned address of the value to update atomically. @result The value before the bitwise operation

macroOSBitAndAtomic

#define OSBitAndAtomic(a, b) (OSBitAndAtomic(a, __SAFE_CAST_PTR(volatile UInt32*,b)))

functionOSBitAndAtomic16

extern UInt16 OSBitAndAtomic16(UInt32 mask, volatile UInt16 * address)
@function OSBitAndAtomic16 @abstract 16-bit logical and operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSBitAndAtomic16 function logically ands the bits of the specified mask into the value at the specified address and returns the original value. 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. @param mask The mask to logically and with the value. @param address The 2-byte aligned address of the value to update atomically. @result The value before the bitwise operation.

functionOSBitAndAtomic8

extern UInt8 OSBitAndAtomic8(UInt32 mask, volatile UInt8 * address)
@function OSBitAndAtomic8 @abstract 8-bit logical and operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSBitAndAtomic8 function logically ands the bits of the specified mask into the value at the specified address and returns the original value. 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. @param mask The mask to logically and with the value. @param address The address of the value to update atomically. @result The value before the bitwise operation.

functionOSBitOrAtomic

extern UInt32 OSBitOrAtomic(UInt32 mask, volatile UInt32 * address)
@function OSBitOrAtomic @abstract 32-bit logical or operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSBitOrAtomic function logically ors the bits of the specified mask into the value at the specified address and returns the original value. 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. @param mask The mask to logically or with the value. @param address The 4-byte aligned address of the value to update atomically. @result The value before the bitwise operation.

macroOSBitOrAtomic

#define OSBitOrAtomic(a, b) (OSBitOrAtomic(a, __SAFE_CAST_PTR(volatile UInt32*,b)))

functionOSBitOrAtomic16

extern UInt16 OSBitOrAtomic16(UInt32 mask, volatile UInt16 * address)
@function OSBitOrAtomic16 @abstract 16-bit logical or operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSBitOrAtomic16 function logically ors the bits of the specified mask into the value at the specified address and returns the original value. 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. @param mask The mask to logically or with the value. @param address The 2-byte aligned address of the value to update atomically. @result The value before the bitwise operation.

functionOSBitOrAtomic8

extern UInt8 OSBitOrAtomic8(UInt32 mask, volatile UInt8 * address)
@function OSBitOrAtomic8 @abstract 8-bit logical or operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 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. @discussion The OSBitOrAtomic8 function logically ors the bits of the specified mask into the value at the specified address and returns the original value. @param mask The mask to logically or with the value. @param address The address of the value to update atomically. @result The value before the bitwise operation.

functionOSBitXorAtomic

extern UInt32 OSBitXorAtomic(UInt32 mask, volatile UInt32 * address)
@function OSBitXorAtomic @abstract 32-bit logical xor operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 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. @discussion The OSBitXorAtomic function logically xors the bits of the specified mask into the value at the specified address and returns the original value. @param mask The mask to logically or with the value. @param address The 4-byte aligned address of the value to update atomically. @result The value before the bitwise operation.

macroOSBitXorAtomic

#define OSBitXorAtomic(a, b) (OSBitXorAtomic(a, __SAFE_CAST_PTR(volatile UInt32*,b)))

functionOSBitXorAtomic16

extern UInt16 OSBitXorAtomic16(UInt32 mask, volatile UInt16 * address)
@function OSBitXorAtomic16 @abstract 16-bit logical xor operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion The OSBitXorAtomic16 function logically xors the bits of the specified mask into the value at the specified address and returns the original value. 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. @param mask The mask to logically or with the value. @param address The 2-byte aligned address of the value to update atomically. @result The value before the bitwise operation.

functionOSBitXorAtomic8

extern UInt8 OSBitXorAtomic8(UInt32 mask, volatile UInt8 * address)
@function OSBitXorAtomic8 @abstract 8-bit logical xor operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 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. @discussion The OSBitXorAtomic8 function logically xors the bits of the specified mask into the value at the specified address and returns the original value. @param mask The mask to logically or with the value. @param address The address of the value to update atomically. @result The value before the bitwise operation.

functionOSTestAndSet

extern Boolean OSTestAndSet(UInt32 bit, volatile UInt8 * startAddress)
@function OSTestAndSet @abstract Bit test and set operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. 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. @discussion 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. @param bit The bit number in the range 0 through 7. Bit 0 is the most significant. @param startAddress The address of the byte to update atomically. @result true if the bit was already set, false otherwise.

functionOSTestAndClear

extern Boolean OSTestAndClear(UInt32 bit, volatile UInt8 * startAddress)
@function OSTestAndClear @abstract Bit test and clear operation, performed atomically with respect to all devices that participate in the coherency architecture of the platform. @discussion 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. 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. @param bit The bit number in the range 0 through 7. Bit 0 is the most significant. @param startAddress The address of the byte to update atomically. @result true if the bit was already clear, false otherwise.

typedefOSSpinLock

@typedef OSSpinLock @abstract Data type for a spinlock. @discussion You should always initialize a spinlock to OS_SPINLOCK_INIT before using it.
typedef SInt32 OSSpinLock

functionOSSynchronizeIO

extern void OSSynchronizeIO(void)
@function OSSynchronizeIO @abstract The OSSynchronizeIO routine ensures orderly load and store operations to noncached memory mapped I/O devices. @discussion The OSSynchronizeIO routine ensures orderly load and store operations to noncached memory mapped I/O devices. It executes the eieio instruction on PowerPC processors.