00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 namespace drizzled {
00023 namespace internal {
00024
00025 template<typename T, typename D>
00026 class gcc_traits
00027 {
00028
00029 public:
00030 typedef T value_type;
00031
00032 gcc_traits() {}
00033
00034 inline value_type add_and_fetch(volatile value_type *value, D addend )
00035 {
00036 return __sync_add_and_fetch(value, addend);
00037 }
00038
00039 inline value_type fetch_and_add(volatile value_type *value, D addend )
00040 {
00041 return __sync_fetch_and_add(value, addend);
00042 }
00043
00044 inline value_type fetch_and_increment(volatile value_type *value)
00045 {
00046 return __sync_fetch_and_add(value, 1);
00047 }
00048
00049 inline value_type fetch_and_decrement(volatile value_type *value)
00050 {
00051 return __sync_fetch_and_sub(value, 1);
00052 }
00053
00054 inline value_type fetch_and_store(volatile value_type *value,
00055 value_type new_value)
00056 {
00057 return __sync_lock_test_and_set(value, new_value);
00058 }
00059
00060 inline bool compare_and_swap(volatile value_type *value,
00061 value_type new_value,
00062 value_type comparand )
00063 {
00064 return __sync_bool_compare_and_swap(value, comparand, new_value);
00065 }
00066
00067 inline value_type fetch(const volatile value_type *value) const volatile
00068 {
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 return __sync_fetch_and_add(const_cast<value_type *>(value), 0);
00080 }
00081
00082 inline value_type store_with_release(volatile value_type *value,
00083 value_type new_value)
00084 {
00085 *value= new_value;
00086 return *value;
00087 }
00088
00089 };
00090
00091
00092 }
00093 }
00094