[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Kernel and Subsystems, Volume 1

fetch_and_add Kernel Service

Purpose

Increments a single word variable atomically.

Syntax

#include <sys/atomic_op.h>
int fetch_and_add ( word_addr, value)
atomic_p word_addr;
int value;

Parameters

word_addr Specifies the address of the word variable to be incremented.
value Specifies the value to be added to the word variable.

Description

The fetch_and_add kernel service atomically increments a single word. This operation is useful when a counter variable is shared between several kernel threads, since it ensures that the fetch, update, and store operations used to increment the counter occur atomically (are not interruptible).

Note
The word variable must be aligned on a full word boundary.

Execution Environment

The fetch_and_add kernel service can be called from either the process or interrupt environment.

Return Values

The fetch_and_add kernel service returns the original value of the word.

Related Information

The fetch_and_and kernel service, fetch_and_or kernel service, compare_and_swap kernel service.

Locking Kernel Services in AIX 5L Version 5.2 Kernel Extensions and Device Support Programming Concepts

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]