---
name: "ACE_Atomic_Op"
section: "3"
platform: "linux"
package: "libace-doc"
version: "5.0.7-4"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/ACE_Atomic_Op"
---

# ACE\_Atomic\_Op(3)

Transparently parameterizes synchronization into basic arithmetic operations.

## NAME

ACE\_Atomic\_Op -  Transparently parameterizes synchronization into basic arithmetic operations.

## SYNOPSIS

```
#include <ace/Synch_T.h>
template<class ACE_LOCK, class TYPE>
class ACE_Atomic_Op
{
  public:
    ACE_Atomic_Op (void);
    ACE_Atomic_Op (const TYPE &c);
    TYPE operator++ (void);
    TYPE operator++ (int);
    TYPE operator+= (const TYPE &i);
    TYPE operator-- (void);
    TYPE operator-- (int);
    TYPE operator-= (const TYPE &i);
    int operator== (const TYPE &i) const;
    int operator!= (const TYPE &i) const;
    int operator>= (const TYPE &i) const;
    int operator> (const TYPE &rhs) const;
    int operator<= (const TYPE &rhs) const;
    int operator< (const TYPE &rhs) const;
    void operator= (const TYPE &i);
    void operator= (const ACE_Atomic_Op<ACE_LOCK, TYPE> &rhs);
    TYPE value (void) const;
    void dump (void) const;
    ACE_Atomic_Op (const ACE_Atomic_Op<ACE_LOCK, TYPE> &);
    ACE_LOCK &mutex (void);
    TYPE &value_i (void);
  private:
    ACE_LOCK mutex_;
    TYPE value_;
};
```

## DESCRIPTION

This class is described in an article in the July/August 1994 issue of the C++ Report magazine.  It implements a templatized version of the Decorator pattern from the GoF book.

## Initialization methods.

```
ACE_Atomic_Op (void);
```

Initialize value\_ to 0.

```
ACE_Atomic_Op (const TYPE &c);
```

Initialize value\_ to c.

## Accessors.

```
TYPE operator++ (void);
```

Atomically pre-increment value\_.

```
TYPE operator++ (int);
```

Atomically post-increment value\_.

```
TYPE operator+= (const TYPE &i);
```

Atomically increment value\_ by i.

```
TYPE operator-- (void);
```

Atomically pre-decrement value\_.

```
TYPE operator-- (int);
```

Atomically post-decrement value\_.

```
TYPE operator-= (const TYPE &i);
```

Atomically decrement value\_ by i.

```
int operator== (const TYPE &i) const;
```

Atomically compare value\_ with i.

```
int operator!= (const TYPE &i) const;
```

Atomically compare value\_ with i.

```
int operator>= (const TYPE &i) const;
```

Atomically check if value\_ greater than or equal to i.

```
int operator> (const TYPE &rhs) const;
```

Atomically check if value\_ greater than i.

```
int operator<= (const TYPE &rhs) const;
```

Atomically check if value\_ less than or equal to i.

```
int operator< (const TYPE &rhs) const;
```

Atomically check if value\_ less than i.

```
void operator= (const TYPE &i);
```

Atomically assign i to value\_.

```
void operator= (const ACE_Atomic_Op<ACE_LOCK, TYPE> &rhs);
```

Atomically assign rhs to value\_.

```
TYPE value (void) const;
```

Explicitly return value\_.

```
void dump (void) const;
```

Dump the state of an object.

ACE\_ALLOC\_HOOK\_DECLARE; Declare the dynamic allocation hooks.

```
ACE_Atomic_Op (const ACE_Atomic_Op<ACE_LOCK, TYPE> &);
```

Manage copying...

```
ACE_LOCK &mutex (void);
```

Returns a reference to the underlying ACE\_LOCK.  This makes it possible to acquire the lock explicitly, which can be useful in some cases if you instantiate the ACE\_Atomic\_Op with an ACE\_Recursive\_Mutex or ACE\_Process\_Mutex.  NOTE: the right name would be lock\_, but HP/C++ will choke on that!

```
TYPE &value_i (void);
```

Explicitly return value\_ (by reference).  This gives the user full, unrestricted access to the underlying value.  This method will usually be used in conjunction with explicit access to the lock.  Use with care ;-)

## AUTHOR

Doug Schmidt

## LIBRARY

ace
