Drizzled Public API Documentation

gcc_traits.h
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2009 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #pragma once
21 
22 namespace drizzled {
23 namespace internal {
24 
25 template<typename T, typename D>
27 {
28 public:
29  typedef T value_type;
30 
31  gcc_traits() {}
32 
33  inline value_type add_and_fetch(volatile value_type *value, D addend )
34  {
35  return __sync_add_and_fetch(value, addend);
36  }
37 
38  inline value_type fetch_and_add(volatile value_type *value, D addend )
39  {
40  return __sync_fetch_and_add(value, addend);
41  }
42 
43  inline value_type fetch_and_increment(volatile value_type *value)
44  {
45  return __sync_fetch_and_add(value, 1);
46  }
47 
48  inline value_type fetch_and_decrement(volatile value_type *value)
49  {
50  return __sync_fetch_and_sub(value, 1);
51  }
52 
53  inline value_type fetch_and_store(volatile value_type *value,
54  value_type new_value)
55  {
56  return __sync_lock_test_and_set(value, new_value);
57  }
58 
59  inline bool compare_and_swap(volatile value_type *value,
60  value_type new_value,
61  value_type comparand )
62  {
63  return __sync_bool_compare_and_swap(value, comparand, new_value);
64  }
65 
66  inline value_type fetch(const volatile value_type *value) const volatile
67  {
68  /*
69  * This is necessary to ensure memory barriers are respected when
70  * simply returning the value pointed at. However, this does not
71  * compile on ICC.
72  *
73  * @todo
74  *
75  * Look at how to rewrite the below to something that ICC feels is
76  * OK and yet respects memory barriers.
77  */
78  return __sync_fetch_and_add(const_cast<value_type *>(value), 0);
79  }
80 
81  inline value_type store_with_release(volatile value_type *value,
82  value_type new_value)
83  {
84  *value= new_value;
85  return *value;
86  }
87 
88 }; /* gcc_traits */
89 
90 
91 } /* namespace internal */
92 } /* namespace drizzled */
TODO: Rename this file - func.h is stupid.