uscas, uscas32 - compare and swap operator
int uscas(void *destp, ptrdiff_t old, ptrdiff_t new, usptr_t *u);
int uscas32(void *destp, int32_t old, int32_t new, usptr_t *u);
uscas emulates a hardware compare and swap instruction. It works on both
single and multi-processor machines. The exact algorithm used depends on
the chip and system type. uscas checks that the contents of destp are
equal to old and if they are, atomically changes the contents of destp to
new. If the contents are not the same, a zero is returned and the
operation may be repeated. Note that even with one process performing
this algorithm, the compare and swap operation may fail, so the caller
must always be prepared to loop. u points to a previously set up arena
uscas does a compare and swap on 32-bits for 32-bit processes and 64-bits
for 64-bit processes.
uscas32 does a compare and swap on 32-bits regardless of the type of the
acquire_lock(3), usinit(3P), ussetlock(3P), uspsema(3P).
A value of 1 returned when a successful compare and swap has been
performed. Otherwise 0 is returned. There are no errors.
PPPPaaaaggggeeee 1111 [ Back ]