1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
5
* Copyright 2005-2008 Intel Corporation. All Rights Reserved.
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; version 2 of the License.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#ifndef DRIZZLED_ATOMICS_H
22
#define DRIZZLED_ATOMICS_H
24
#if defined(HAVE_LIBTBB)
25
# include <tbb/atomic.h>
28
# if defined(__SUNPRO_CC)
29
# include <drizzled/atomic/sun_studio.h>
31
# if defined(HAVE_GCC_ATOMIC_BUILTINS) || defined(__SUNPRO_CC)
32
# include <drizzled/atomic/gcc_traits.h>
33
# define ATOMIC_TRAITS internal::gcc_traits
34
# else /* use pthread impl */
36
# include <drizzled/atomic/pthread_traits.h>
37
# define ATOMIC_TRAITS internal::pthread_traits
46
template<typename I> // Primary template
51
template<typename I, typename D, typename T >
52
class atomic_impl: private atomic_base<I>
59
value_type fetch_and_add( D addend )
61
return traits.fetch_and_add(&this->my_value, addend);
64
value_type fetch_and_increment()
66
return traits.fetch_and_increment(&this->my_value);
69
value_type fetch_and_decrement()
71
return traits.fetch_and_decrement(&this->my_value);
74
value_type fetch_and_store( value_type value )
76
return traits.fetch_and_store(&this->my_value, value);
79
value_type compare_and_swap( value_type value, value_type comparand )
81
return traits.compare_and_swap(&this->my_value, value, comparand);
84
operator value_type() const volatile
86
return traits.fetch(&this->my_value);
89
value_type& _internal_reference() const
91
return this->my_value;
95
value_type store_with_release( value_type rhs )
97
return traits.store_with_release(&this->my_value, rhs);
101
value_type operator+=( D addend )
103
return fetch_and_add(addend)+addend;
106
value_type operator-=( D addend )
108
// Additive inverse of addend computed using binary minus,
109
// instead of unary minus, for sake of avoiding compiler warnings.
110
return operator+=(D(0)-addend);
113
value_type operator++() {
114
return fetch_and_add(1)+1;
117
value_type operator--() {
118
return fetch_and_add(D(-1))-1;
121
value_type operator++(int) {
122
return fetch_and_add(1);
125
value_type operator--(int) {
126
return fetch_and_add(D(-1));
131
} /* namespace internal */
133
//! Primary template for atomic.
134
/** See the Reference for details.
135
@ingroup synchronization */
140
#define __TBB_DECL_ATOMIC(T) \
141
template<> struct atomic<T> \
142
: internal::atomic_impl<T,T,ATOMIC_TRAITS<T,T> > { \
143
atomic<T>() : internal::atomic_impl<T,T,ATOMIC_TRAITS<T,T> >() {} \
144
T operator=( T rhs ) { return store_with_release(rhs); } \
147
__TBB_DECL_ATOMIC(long long)
148
__TBB_DECL_ATOMIC(unsigned long long)
149
__TBB_DECL_ATOMIC(long)
150
__TBB_DECL_ATOMIC(unsigned long)
151
__TBB_DECL_ATOMIC(unsigned int)
152
__TBB_DECL_ATOMIC(int)
153
__TBB_DECL_ATOMIC(unsigned short)
154
__TBB_DECL_ATOMIC(short)
155
__TBB_DECL_ATOMIC(char)
156
__TBB_DECL_ATOMIC(signed char)
157
__TBB_DECL_ATOMIC(unsigned char)
160
#endif /* defined(HAVE_LIBTBB) */
162
#endif /* DRIZZLED_ATOMIC_H */