Important: The information in this document is obsolete and should not be used for new development.
OTCompareAndSwap16
Atomically compares two 16-bit values and changes one of these values if they are the same.C INTERFACE
Boolean OTCompareAndSwap16( UInt32 oldVal, UInt32 newVal, UInt16* where)C++ INTERFACE
None. C++ applications use the C interface to this function.PARAMETERS
oldVal- The 16-bit value being compared to the value referenced by the
whereparameter.newVal- The value to be assigned to the 16-bit value referenced by the
whereparameter.where- A reference to the 16-bit value being compared to that specified by the
oldValparameter.- function result
- Returns
trueif the swap is done.DISCUSSION
This function compares the least significant 16 bits ofoldValwith the value referenced by thewhereparameter. If the two values are the same, the function replaces the 16-bit value referenced by thewhereparameter with the value specified by thenewValparameter and it returnstrue. If the two values are not the same, no swap occurs and the function returnsfalse.The entire compare and swap operation is atomic.
Use the
- WARNING
- The pointer
wheremust be at an address where the second byte of the 16 bit value is not in a different 4-byte cell than the first byte (i.e. (where % 4) != 3).![]()
OTCompareAndSwap32function to compare two 32-bit values and set one if they are the same.Use the
OTCompareAndSwap8function to compare two 8-bit values and set one if they are the same.