~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/atomics.h

  • Committer: Monty Taylor
  • Date: 2009-07-17 17:13:52 UTC
  • mto: (1090.4.3 build-cleanup)
  • mto: This revision was merged to the branch mainline in revision 1098.
  • Revision ID: mordred@inaugust.com-20090717171352-fxcdsacvsmtzs4jv
Fixed manpage warnings. Make debian lintian happy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#ifndef DRIZZLED_ATOMICS_H
22
22
#define DRIZZLED_ATOMICS_H
23
23
 
 
24
#if defined(HAVE_LIBTBB)
 
25
# include <tbb/atomic.h>
 
26
/* We're actually using the TBB interface directly, but we don't want to tie
 
27
 * the code to a specific implementation. So suck the tbb:: stuff into the
 
28
 * drizzled namespace
 
29
 */
 
30
namespace drizzled {
 
31
  using namespace tbb;
 
32
}
 
33
#else
 
34
 
24
35
# if defined(__SUNPRO_CC)
25
36
#  include <drizzled/atomic/sun_studio.h>
26
37
# endif
31
42
#  define ATOMIC_TRAITS internal::pthread_traits
32
43
# endif
33
44
 
34
 
# if (SIZEOF_SIZE_T >= SIZEOF_LONG_LONG) || (!defined(HAVE_GCC_ATOMIC_BUILTINS) || !defined(__SUNPRO_CC)) || defined(__ppc__)
 
45
# if (SIZEOF_SIZE_T >= SIZEOF_LONG_LONG) || (!defined(HAVE_GCC_ATOMIC_BUILTINS) || !defined(__SUNPRO_CC))
35
46
#  include <pthread.h>
36
47
#  include <drizzled/atomic/pthread_traits.h>
37
48
# endif
45
56
template<typename I>            // Primary template
46
57
struct atomic_base {
47
58
  volatile I my_value;
48
 
  atomic_base() : my_value(0) {}
49
 
  virtual ~atomic_base() {}
50
59
};
51
60
 
52
61
template<typename I, typename D, typename T >
56
65
public:
57
66
  typedef I value_type;
58
67
 
59
 
  atomic_impl() : atomic_base<I>(), traits() {}
60
68
 
61
69
  value_type fetch_and_add( D addend )
62
70
  {
100
108
  }
101
109
 
102
110
public:
103
 
  atomic_impl<I,D,T>& operator+=( D addend )
 
111
  value_type operator+=( D addend )
104
112
  {
105
 
    fetch_and_add(addend)+addend;
106
 
    return *this;
 
113
      return fetch_and_add(addend)+addend;
107
114
  }
108
115
 
109
 
  atomic_impl<I,D,T>& operator-=( D addend )
 
116
  value_type operator-=( D addend )
110
117
  {
111
118
    // Additive inverse of addend computed using binary minus,
112
119
    // instead of unary minus, for sake of avoiding compiler warnings.
113
120
    return operator+=(D(0)-addend);
114
121
  }
115
122
 
116
 
  value_type increment() {
 
123
  value_type operator++() {
117
124
    return fetch_and_add(1)+1;
118
125
  }
119
126
 
120
 
  value_type decrement() {
 
127
  value_type operator--() {
121
128
    return fetch_and_add(D(-1))-1;
122
129
  }
123
130
 
 
131
  value_type operator++(int) {
 
132
    return fetch_and_add(1);
 
133
  }
 
134
 
 
135
  value_type operator--(int) {
 
136
    return fetch_and_add(D(-1));
 
137
  }
124
138
 
125
139
};
126
140
 
133
147
struct atomic {
134
148
};
135
149
 
136
 
/* *INDENT-OFF* */
137
150
#define __DRIZZLE_DECL_ATOMIC(T)                                        \
138
151
  template<> struct atomic<T>                                           \
139
152
  : internal::atomic_impl<T,T,ATOMIC_TRAITS<T,T> > {                    \
140
153
    atomic<T>() : internal::atomic_impl<T,T,ATOMIC_TRAITS<T,T> >() {}   \
141
 
    atomic<T>& operator=( T rhs ) { store_with_release(rhs); return *this; } \
 
154
    T operator=( T rhs ) { return store_with_release(rhs); }            \
142
155
  };
143
 
/* *INDENT-ON* */
144
156
 
145
157
 
146
158
__DRIZZLE_DECL_ATOMIC(long)
157
169
/* 32-bit platforms don't have a GCC atomic operation for 64-bit types,
158
170
 * so we'll use pthread locks to handler 64-bit types on that platforms
159
171
 */
160
 
/* *INDENT-OFF* */
161
 
# if !defined(__ppc__) && (defined(_INT64_TYPE) || defined(_LP64))
 
172
#  if SIZEOF_SIZE_T >= SIZEOF_LONG_LONG
162
173
__DRIZZLE_DECL_ATOMIC(long long)
163
174
__DRIZZLE_DECL_ATOMIC(unsigned long long)
164
175
#  else
172
183
__DRIZZLE_DECL_ATOMIC64(long long)
173
184
__DRIZZLE_DECL_ATOMIC64(unsigned long long)
174
185
#  endif
175
 
/* *INDENT-ON* */
176
186
 
177
187
}
 
188
# endif /* defined(HAVE_LIBTBB) */
178
189
 
179
 
#endif /* DRIZZLED_ATOMICS_H */
 
190
#endif /* DRIZZLED_ATOMIC_H */