atomic.3c (2010 09)
a
atomic(3C) atomic(3C)
NAME
atomic: atomic_swap_8(), atomic_swap_16(), atomic_swap_32(), atomic_swap_64(), atomic_inc_32(),
atomic_inc_64(), atomic_dec_32(), atomic_dec_64(), atomic_cas_8(), atomic_cas_16(), atomic_cas_32(),
atomic_cas_64(), atomic_swap(), atomic_inc(), atomic_dec(), atomic_cas() - atomic APIs
SYNOPSIS
#include <atomic.h>
uint8_t atomic_swap_8(volatile uint8_t *
var, uint8_t newVal);
uint16_t atomic_swap_16(volatile uint16_t *
var, uint16_t newVal);
uint32_t atomic_swap_32(volatile uint32_t *
var, uint32_t newVal);
uint64_t atomic_swap_64(volatile uint64_t *
var, uint64_t newVal);
uint32_t atomic_inc_32(volatile uint32_t *
var);
uint64_t atomic_inc_64(volatile uint64_t *
var);
uint32_t atomic_dec_32(volatile uint32_t *
var);
uint64_t atomic_dec_64(volatile uint64_t *
var);
uint8_t atomic_cas_8(volatile uint8_t *
var, uint8_t cmpVal, uint8_t newVal);
uint16_t atomic_cas_16(volatile uint16_t *
var, uint16_t cmpVal, uint16_t
newVal);
uint32_t atomic_cas_32(volatile uint32_t *
var, uint32_t cmpVal, uint32_t
newVal);
uint64_t atomic_cas_64(volatile uint64_t *
var, uint64_t cmpVal, uint64_t
newVal);
uint64_t atomic_swap(volatile void *
var, uint64_t newVal, int byte_size);
uint64_t atomic_inc(volatile void *
var, int byte_size);
uint64_t atomic_dec(volatile void *
var, int byte_size);
uint64_t atomic_cas(volatile void *
var, uint64_t cmpVal, uint64_t newVal, int
byte_size);
Parameters
var Pointer to a memory location.
newVal The new value to be replaced in the memory location.
cmpVal The value to be compared with the value in the memory location.
byte_size The number of bytes to be considered in the memory location.
Remarks
Atomic APIs are incorporated into a library named
libatomic. Applications need to link with the
libatomic library (-latomic) in order to use these APIs. For example:
cc test_atomic.c -latomic
On PA-RISC systems addresses passed as arguments to these APIs should be from the process private vir-
tual address space. This restriction does not exist on Integrity systems.
DESCRIPTION
The
atomic_swap_8(), atomic_swap_16()
, atomic_swap_32() and atomic_swap_64()
functions perform a swap operation atomically. The 8, 16, 32 or 64 bit value, respectively, pointed to by
var is replaced with newVal. The old value pointed to by var is returned by the functions.
The
atomic_inc_32() and atomic_inc_64() functions atomically increment a 32 or 64 bit value,
respectively, pointed to by var . The old value pointed to by var is returned by the functions.
The
atomic_dec_32() and atomic_dec_64() functions atomically decrement a 32 or 64 bit value,
respectively, pointed to by var . The old value pointed to by var is returned by the functions.
The
atomic_cas_8(), atomic_cas_16(), atomic_cas_32() and atomic_cas_64() func-
tions perform a compare and swap operation atomically. The 8, 16, 32 or 64 bit value, respectively,
HP-UX 11i Version 3: September 2010 − 1 − Hewlett-Packard Company 1