Conditionally updates or returns a single word variable atomically.
#include <sys/atomic_op.h>
boolean_t compare_and_swap (word_addr, old_val_addr, new_val) atomic_p word_addr; int *old_val_addr; int new_val;
The compare_and_swap kernel service performs an atomic (uninterruptible) operation which compares the contents of a single word variable with a stored old value; if equal, a new value is stored in the single word variable, and TRUE is returned, otherwise the old value is set to the current value of the single word variable, and FALSE is returned.
The compare_and_swap kernel service is particularly useful in operations on singly linked lists, where a list pointer must not be updated if it has been changed by another thread since it was read.
Note: The word variable must be aligned on a full word boundary.
The compare_and_swap kernel service can be called from either the process or interrupt environment.
The compare_and_swap kernel service is part of the Base Operating System (BOS) Runtime.
The fetch_and_add kernel service, fetch_and_and kernel service, fetch_and_or kernel service.
Locking Kernel Services in AIX Kernel Extensions and Device Support Programming Concepts