~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/atomics.h

  • Committer: Stewart Smith
  • Date: 2009-06-16 06:55:11 UTC
  • mto: This revision was merged to the branch mainline in revision 1094.
  • Revision ID: stewart@flamingspork.com-20090616065511-ps3ewfxj7918lwy3
rollback.test for MyISAM temp only.
- rename to myisam_rollback to reflect what it's testing
- just use create temporary table

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
27
 
# if !defined(__ICC) && !defined(__clang__) && (defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(__SUNPRO_CC))
 
38
# if defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(__SUNPRO_CC)
28
39
#  include <drizzled/atomic/gcc_traits.h>
29
40
#  define ATOMIC_TRAITS internal::gcc_traits
30
41
# else  /* use pthread impl */
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
 
 
61
 
  value_type add_and_fetch( D addend )
62
 
  {
63
 
    return traits.add_and_fetch(&this->my_value, addend);
64
 
  }
65
68
 
66
69
  value_type fetch_and_add( D addend )
67
70
  {
83
86
    return traits.fetch_and_store(&this->my_value, value);
84
87
  }
85
88
 
86
 
  bool compare_and_swap( value_type value, value_type comparand )
 
89
  value_type compare_and_swap( value_type value, value_type comparand )
87
90
  {
88
91
    return traits.compare_and_swap(&this->my_value, value, comparand);
89
92
  }
105
108
  }
106
109
 
107
110
public:
108
 
  atomic_impl<I,D,T>& operator+=( D addend )
 
111
  value_type operator+=( D addend )
109
112
  {
110
 
    increment(addend);
111
 
    return *this;
 
113
      return fetch_and_add(addend)+addend;
112
114
  }
113
115
 
114
 
  atomic_impl<I,D,T>& operator-=( D addend )
 
116
  value_type operator-=( D addend )
115
117
  {
116
118
    // Additive inverse of addend computed using binary minus,
117
119
    // instead of unary minus, for sake of avoiding compiler warnings.
118
120
    return operator+=(D(0)-addend);
119
121
  }
120
122
 
121
 
  value_type increment()
122
 
  {
123
 
    return add_and_fetch(1);
124
 
  }
125
 
 
126
 
  value_type decrement()
127
 
  {
128
 
    return add_and_fetch(D(-1));
129
 
  }
 
123
  value_type operator++() {
 
124
    return fetch_and_add(1)+1;
 
125
  }
 
126
 
 
127
  value_type operator--() {
 
128
    return fetch_and_add(D(-1))-1;
 
129
  }
 
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
  }
 
138
 
130
139
};
131
140
 
132
141
} /* namespace internal */
138
147
struct atomic {
139
148
};
140
149
 
141
 
/* *INDENT-OFF* */
142
150
#define __DRIZZLE_DECL_ATOMIC(T)                                        \
143
151
  template<> struct atomic<T>                                           \
144
152
  : internal::atomic_impl<T,T,ATOMIC_TRAITS<T,T> > {                    \
145
153
    atomic<T>() : internal::atomic_impl<T,T,ATOMIC_TRAITS<T,T> >() {}   \
146
 
    atomic<T>& operator=( T rhs ) { store_with_release(rhs); return *this; } \
 
154
    T operator=( T rhs ) { return store_with_release(rhs); }            \
147
155
  };
148
 
/* *INDENT-ON* */
149
156
 
150
157
 
151
158
__DRIZZLE_DECL_ATOMIC(long)
162
169
/* 32-bit platforms don't have a GCC atomic operation for 64-bit types,
163
170
 * so we'll use pthread locks to handler 64-bit types on that platforms
164
171
 */
165
 
/* *INDENT-OFF* */
166
 
# if !defined(__ppc__) && (defined(_INT64_TYPE) || defined(_LP64))
 
172
#  if SIZEOF_SIZE_T >= SIZEOF_LONG_LONG
167
173
__DRIZZLE_DECL_ATOMIC(long long)
168
174
__DRIZZLE_DECL_ATOMIC(unsigned long long)
169
175
#  else
177
183
__DRIZZLE_DECL_ATOMIC64(long long)
178
184
__DRIZZLE_DECL_ATOMIC64(unsigned long long)
179
185
#  endif
180
 
/* *INDENT-ON* */
181
186
 
182
187
}
 
188
# endif /* defined(HAVE_LIBTBB) */
183
189
 
184
 
#endif /* DRIZZLED_ATOMICS_H */
 
190
#endif /* DRIZZLED_ATOMIC_H */