Table of Contents
qthread_cas, qthread_cas_ptr - atomically compare-and-swap a value
#include
<qthread.h>
aligned_t
qthread_cas (volatile aligned_t *addr, const aligned_t oldval, const aligned_t
newval);
void *
qthread_cas_ptr (void * volatile * const addr, void * const oldval, void
* const newval);
This function atomically compares the contents
of the memory at addr with the value oldval and if they are the same, writes
newval into that memory. If they are not the same, no change is made. In
either case, the contents of addr are returned. In short, this is an atomic
version of:
if (*addr == oldval) {
*addr = newval;
}
return *addr;
This function uses architecture-specific assembly to achieve
this, or compiler built-in functions, if they exist.
These functions
will return the value of *addr before any assignment is (potentially) performed.
qthread_incr(3)
Table of Contents