fetch_and_and or fetch_and_or Kernel Services

Purpose

Clears and sets bits in a variable atomically.

Syntax

#include <sys/atomic_op.h>

uint fetch_and_and (addr,  mask)
atomic_p addr;uint mask;

ulong fetch_and_andlp (addr,  mask)
atomic_l addr;
ulong mask;

uint fetch_and_or (addr,  mask)
atomic_p addr;
uint mask;

ulong fetch_and_orlp (addr,  mask)
atomic_l addr;
ulong mask;

Parameters

Item Description
addr Specifies the address of the variable whose bits are to be cleared or set.
mask Specifies the bit mask which is to be applied to the variable.

Description

The fetch_and_and and fetch_and_or kernel services respectively clear and set bits in a variable, according to a bit mask, as a single atomic operation. The fetch_and_and service clears bits in the variable which correspond to clear bits in the bit mask, and the fetch_and_or service sets bits in the variable which correspond to set bits in the bit mask.

The fetch_and_add and fetch_and_or kernel services operate on a single word (32 bit) variable while the fetch_and_addlp and fetch_and_orlp kernel services operate on a double word (64 bit) variable.

These operations are useful when a variable containing bit flags is shared between several kernel threads, because they ensure that the fetch, update, and store operations used to clear or set a bit in the variable occur atomically (are not interruptible).

Note:
  • For the fetch_and_and and fetch_and_or kernel services, the single word containing the bit flags must be aligned on a full word (32 bit) boundary.
  • For the fetch_and_addlp and fetch_and_orlp kernel services, the double word containing the bit flags must be aligned on a double word (64 bit) boundary.

Execution Environment

The fetch_and_and and fetch_and_or kernel services can be called from either the process or interrupt environment.

Return Values

The fetch_and_and and fetch_and_or kernel services return the original value of the variable.