cds() — Compare double and swap

Standards

Standards / Extensions C or C++ Dependencies
C Library both  

Format

#include <stdlib.h>

int cds(cds_t *oldptr, cds_t *curptr, cds_t newwords);

General description

The cds() built-in function compares the 8-byte value pointed to by oldptr to the 8-byte value pointed to by curptr. If they are equal, the 8-byte value newwords is copied into the location pointed to by curptr. If they are unequal, the value pointed to by curptr is copied into the location pointed to by oldptr.

To avoid infringing on the user's name space, this nonstandard function is exposed only when you use the compiler option, LANGLVL(EXTENDED). When you use LANGLVL(EXTENDED) any relevant information in the header is also exposed.

The function uses the COMPARE DOUBLE AND SWAP (CDS) instructions, which can be used in multiprogramming or multiprocessing environments to serialize access to counters, flags, control words, and other common storage areas. For a detailed description, see topics "XL C/C++ Macros" and "Function support table" in the z/Architecture Principles of Operation on number representation and instruction.

Returned value

cds() returns 0 if the 8-byte value pointed to by oldptr is equal to the 8-byte value pointed to by curptr.

Otherwise cds() returns 1.

Related information