Interface __PrefixCMPXCHGSuffix
Inline function
Space | User/kernel |
Context | Sync/async/rt-irq |
May block | No |
SPL | Any |
Dynamic memory | No |
#include <ARCH/BITOPS.H>
static __finline__ long __PrefixCMPXCHGSuffix(type *ptr, type old, type new);
Description
This family of inline functions compare a memory location with old argument and if they are equal, they write new argument to the memory location. This operation is performed atomically.
Parts of function name — Prefix and Suffix determine atomicity requirements and data type.
Arguments
- Prefix — This is the part of function name. It specifies atomicity of the operation.
- empty — Perform an operation that is atomic with respect to events on the CPU itself (ASTs or real time interrupts) but it is not atomic with respect to other CPUs or busmasters.
- LOCK_ — The operation will contain lock prefix, making it atomic with respect to other CPUs and bus mastering devices.
- Suffix — This is the part of function name. It determines argument types:
- C — argument has the type signed or unsigned char or __s8 or __u8.
- I — argument has the type signed or unsigned int.
- L — argument has the type signed or unsigned long.
- 32 — argument has the type __u32 or __s32.
- 64 — argument has the type __u64 or __s64. This variant is available only if macro __CMPXCHG64_AVAILABLE returns non-zero. If this macro returns zero, 64-bit CMPXCHG must not be performed, because it would cause a crash.
- ptr — Pointer pointing to a memory location that should be atomically changed.
- old — Compare memory location with this value.
- new — Write this value to the memory location, if it was equal to old.
Returns
This function returns non-zero if the compare didn't match (in that case the memory location is unchanged) and zero if it matched (in that case, new was written to the memory location). It may return any non-zero value in the case of mismatch, do not pass the value directly to __likely or __unlikely because they expect int
argument — use if (__likely(__CMPXCHG...(...) != 0))
.
See also
__PrefixOpSuffix, __PrefixOpSuffixCondition, __CMPXCHG64_AVAILABLE