PCL
pcl::AtomicInt Class Reference

Atomic operations on integers. More...

#include <Atomic.h>

Public Member Functions

 AtomicInt (const AtomicInt &)=default
 
 AtomicInt (int value=0)
 
void Decrement ()
 
bool Dereference ()
 
int FetchAndAdd (int valueToAdd)
 
int FetchAndStore (int newValue)
 
void Increment ()
 
int Load ()
 
 operator int () const
 
bool operator! () const
 
bool operator!= (int x) const
 
AtomicIntoperator= (const AtomicInt &)=default
 
AtomicIntoperator= (int x)
 
bool operator== (int x) const
 
bool Reference ()
 
void Store (int newValue)
 
bool TestAndSet (int expectedValue, int newValue)
 

Detailed Description

AtomicInt allows non-blocking synchronization of multithreaded code with respect to reference counting and other critical operations in parallel algorithm implementations. This class is used extensively by PCL code to implement copy-on-write shared containers and container operations in a thread-safe way. An example is the ReferenceCounter class, which is at the hearth of most PCL container and image classes.

AtomicInt implements the following synchronization primitives on integers:

reference
dereference
test-and-set
fetch-and-store
fetch-and-add

See also
ReferenceCounter

Definition at line 94 of file Atomic.h.

Constructor & Destructor Documentation

◆ AtomicInt() [1/2]

pcl::AtomicInt::AtomicInt ( int  value = 0)
inline

Constructs an AtomicInt instance with the specified value. When not explicitly specified, the default value is zero.

Definition at line 102 of file Atomic.h.

◆ AtomicInt() [2/2]

pcl::AtomicInt::AtomicInt ( const AtomicInt )
default

Copy constructor.

Member Function Documentation

◆ Decrement()

void pcl::AtomicInt::Decrement ( )
inline

Atomic decrement operation.

Decrements the value of this object as an atomic operation.

Note
This operation is guaranteed to be atomic on all supported platforms and architectures.

Definition at line 228 of file Atomic.h.

◆ Dereference()

bool pcl::AtomicInt::Dereference ( )
inline

Atomic dereference operation.

Decrements the value of this object as an atomic operation. Returns true if the resulting value after decrementing this object is nonzero.

Note
This operation is guaranteed to be atomic on all supported platforms and architectures.

Definition at line 275 of file Atomic.h.

◆ FetchAndAdd()

int pcl::AtomicInt::FetchAndAdd ( int  valueToAdd)
inline

Atomic fetch-and-add operation. Adds valueToAdd to this object and returns the initial value before addition, as an atomic operation.

Note
This operation is guaranteed to be atomic on all supported platforms and architectures.

Definition at line 347 of file Atomic.h.

◆ FetchAndStore()

int pcl::AtomicInt::FetchAndStore ( int  newValue)
inline

Atomic fetch-and-store operation.

Assigns newValue to this object and returns the initial value before assignment, as an atomic operation.

Note
This operation is guaranteed to be atomic on all supported platforms and architectures.

Definition at line 327 of file Atomic.h.

◆ Increment()

void pcl::AtomicInt::Increment ( )
inline

Atomic increment operation.

Increments the value of this object as an atomic operation.

Note
This operation is guaranteed to be atomic on all supported platforms and architectures.

Definition at line 207 of file Atomic.h.

◆ Load()

int pcl::AtomicInt::Load ( )
inline

Atomic load operation.

Returns the current value of this atomic integer.

Note
The integer load operation is guaranteed to be atomic on all supported platforms and architectures.

Definition at line 181 of file Atomic.h.

◆ operator int()

pcl::AtomicInt::operator int ( ) const
inline

Returns the current value of this atomic integer.

Note
This operation is not guaranteed to be atomic.

Definition at line 124 of file Atomic.h.

◆ operator!()

bool pcl::AtomicInt::operator! ( ) const
inline

Logical negation operator. Returns true iff this atomic integer is zero.

Note
This operation is not guaranteed to be atomic.

Definition at line 134 of file Atomic.h.

◆ operator!=()

bool pcl::AtomicInt::operator!= ( int  x) const
inline

Inequality operator. Returns true iff this atomic integer is not equal to an integer x.

Note
This operation is not guaranteed to be atomic.

Definition at line 156 of file Atomic.h.

◆ operator=() [1/2]

AtomicInt& pcl::AtomicInt::operator= ( const AtomicInt )
default

Copy assignment operator. Returns a reference to this object.

◆ operator=() [2/2]

AtomicInt& pcl::AtomicInt::operator= ( int  x)
inline

Integer assignment operator. Assigns the specified integer x to this atomic integer. Returns a reference to this object.

Note
This operation is not guaranteed to be atomic.

Definition at line 167 of file Atomic.h.

◆ operator==()

bool pcl::AtomicInt::operator== ( int  x) const
inline

Equality operator. Returns true iff this atomic integer is equal to an integer x.

Note
This operation is not guaranteed to be atomic.

Definition at line 145 of file Atomic.h.

◆ Reference()

bool pcl::AtomicInt::Reference ( )
inline

Atomic reference operation.

Increments the value of this object as an atomic operation. Returns true if the resulting value after incrementing this object is nonzero.

Note
This operation is guaranteed to be atomic on all supported platforms and architectures.

Definition at line 250 of file Atomic.h.

◆ Store()

void pcl::AtomicInt::Store ( int  newValue)
inline

Atomic store operation.

Assigns the specified newValue to this object.

Note
The integer store operation is guaranteed to be atomic on all supported platforms and architectures.

Definition at line 194 of file Atomic.h.

Referenced by pcl::AutoReentrancyGuard::~AutoReentrancyGuard().

◆ TestAndSet()

bool pcl::AtomicInt::TestAndSet ( int  expectedValue,
int  newValue 
)
inline

Atomic test-and-set operation.

If the current value of this object is equal to expectedValue, this function assigns newValue to this object and returns true. If the current value is not equal to expectedValue, this function performs no operation and returns false.

Note
This operation is guaranteed to be atomic on all supported platforms and architectures.

Definition at line 302 of file Atomic.h.

Referenced by pcl::AutoReentrancyGuard::AutoReentrancyGuard().


The documentation for this class was generated from the following file: