summaryrefslogtreecommitdiff
path: root/ACE/ace/Atomic_Op_GCC_T.h
blob: 751387f9ce7779cd4f7b2f6145f292737f74e31a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// -*- C++ -*-

//=============================================================================
/**
 *  @file    Atomic_Op_GCC_T.h
 *
 *  @author Johnny Willemsen  <jwillemsen@remedy.nl
 */
//=============================================================================

#ifndef ACE_ATOMIC_OP_GCC_T_H
#define ACE_ATOMIC_OP_GCC_T_H
#include /**/ "ace/pre.h"

#include /**/ "ace/config-all.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Thread_Mutex.h"
#include "ace/ACE_export.h"

#if defined (ACE_HAS_GCC_ATOMIC_BUILTINS) && (ACE_HAS_GCC_ATOMIC_BUILTINS == 1)

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

/**
 * @brief Specialization of ACE_Atomic_Op for platforms that
 *        support atomic integer operations.
 *
 * Specialization of ACE_Atomic_Op for platforms that support atomic
 * integer operations.
 */
template<typename T>
class ACE_Export ACE_Atomic_Op_GCC
{
public:
  /// Atomically pre-increment @c value_.
  T operator++ ();

  /// Atomically post-increment @c value_.
  T operator++ (int);

  /// Atomically increment @c value_ by rhs.
  T operator+= (T rhs);

  /// Atomically pre-decrement @c value_.
  T operator-- ();

  /// Atomically post-decrement @c value_.
  T operator-- (int);

  /// Atomically decrement @c value_ by rhs.
  T operator-= (T rhs);

  /// Atomically compare @c value_ with rhs.
  bool operator== (T rhs) const;

  /// Atomically compare @c value_ with rhs.
  bool operator!= (T rhs) const;

  /// Atomically check if @c value_ greater than or equal to rhs.
  bool operator>= (T rhs) const;

  /// Atomically check if @c value_ greater than rhs.
  bool operator> (T rhs) const;

  /// Atomically check if @c value_ less than or equal to rhs.
  bool operator<= (T rhs) const;

  /// Atomically check if @c value_ less than rhs.
  bool operator< (T rhs) const;

  /// Exchange value with @a newval.
  T exchange (T newval);

  /// Explicitly return @c value_.
  T value () const;

  /// Dump the state of an object.
  void dump () const;

  /// Explicitly return @c value_ (by reference).
  volatile T &value_i ();

  // ACE_ALLOC_HOOK_DECLARE;
  // Declare the dynamic allocation hooks.

protected:
  /// Atomically assign rhs to @c value_.
  ACE_Atomic_Op_GCC<T> &operator= (T rhs);

  /// Atomically assign <rhs> to @c value_.
  ACE_Atomic_Op_GCC<T> &operator= (const ACE_Atomic_Op_GCC<T> &rhs);

  /// Initialize @c value_ to 0.
  ACE_Atomic_Op_GCC ();

  /// Initialize @c value_ to c.
  ACE_Atomic_Op_GCC (T c);

  /// Manage copying...
  ACE_Atomic_Op_GCC (const ACE_Atomic_Op_GCC<T> &c);

private:
  // This function cannot be supported by this template specialization.
  // If you need access to an underlying lock, use the ACE_Atomic_Op_Ex
  // template instead.
  ACE_Thread_Mutex &mutex ();

private:
  /// Current object decorated by the atomic op.
  volatile T value_;
};

ACE_END_VERSIONED_NAMESPACE_DECL

#if defined (__ACE_INLINE__)
#include "ace/Atomic_Op_GCC_T.inl"
#endif /* __ACE_INLINE__ */

#include "ace/Atomic_Op_GCC_T.cpp"

#endif /* ACE_HAS_GCC_ATOMIC_BUILTINS */

#include /**/ "ace/post.h"
#endif /*ACE_ATOMIC_OP_GCC_T_H*/