Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Networking With Open Transport / Part 2 - Open Transport Reference
Chapter 27 - Utilities Reference / Functions
Atomic Operations /


OTCompareAndSwap32

Atomically compares two 32-bit values and changes one of these values if they are the same.

C INTERFACE
Boolean OTCompareAndSwap32(
                     UInt32 oldVal,
                     UInt32 newVal,
                     UInt32* where)
C++ INTERFACE
None. C++ applications use the C interface to this function.

PARAMETERS
oldVal
The 32-bit value being compared to the value referenced by the where parameter.
newVal
The value to be assigned to the long-word referenced by the where parameter.
where
A reference to the 32-bit value being compared to that specified by the oldVal parameter.
function result
Returns true if the swap is done.
DISCUSSION
This function compares the value specified by the oldVal parameter with the value referenced by the where parameter. If the two values are the same, the function replaces the long-word referenced by the where parameter with the value specified by the newVal parameter and it returns true. If the two values are not the same, no swap occurs and the function returns false.

The entire compare and swap operation is atomic.

WARNING
The pointer where must be on a 4-byte boundary, or calling this function may hang the machine.
Use the OTCompareAndSwapPtr function to compare two pointer values and set one if they are the same.

Use the OTCompareAndSwap16 function to compare two 16-bit values and set one if they are the same.

Use the OTCompareAndSwap8 function to compare two 8-bit values and set one if they are the same.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
15 JAN 1998