[ Previous | Next | Contents | Home | Search ]
AIX Version 4.3 Kernel and Subsystems Technical Reference, 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.

Implementation Specifics

The fetch_and_add kernel service is part of the Base Operating System (BOS) Runtime.

Related Information

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

Locking Kernel Services in AIX Kernel Extensions and Device Support Programming Concepts


[ Previous | Next | Contents | Home | Search ]