~drizzle-trunk/drizzle/development

910.5.2 by Monty Taylor
Applied atomic patch to current tree.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
910.5.2 by Monty Taylor
Applied atomic patch to current tree.
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
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
20
#pragma once
910.5.2 by Monty Taylor
Applied atomic patch to current tree.
21
968.2.3 by Monty Taylor
Replacd use of tbb:: namespace with drizzled::
22
namespace drizzled {
910.5.2 by Monty Taylor
Applied atomic patch to current tree.
23
namespace internal {
24
25
template<typename T, typename D>
26
class gcc_traits
27
{
28
29
public:
30
  typedef T value_type;
31
32
  gcc_traits() {}
33
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
34
  inline value_type add_and_fetch(volatile value_type *value, D addend )
35
  {
36
    return __sync_add_and_fetch(value, addend);
37
  }
38
910.5.2 by Monty Taylor
Applied atomic patch to current tree.
39
  inline value_type fetch_and_add(volatile value_type *value, D addend )
40
  {
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
41
    return __sync_fetch_and_add(value, addend);
910.5.2 by Monty Taylor
Applied atomic patch to current tree.
42
  }
43
44
  inline value_type fetch_and_increment(volatile value_type *value)
45
  {
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
46
    return __sync_fetch_and_add(value, 1);
910.5.2 by Monty Taylor
Applied atomic patch to current tree.
47
  }
48
49
  inline value_type fetch_and_decrement(volatile value_type *value)
50
  {
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
51
    return __sync_fetch_and_sub(value, 1);
910.5.2 by Monty Taylor
Applied atomic patch to current tree.
52
  }
53
54
  inline value_type fetch_and_store(volatile value_type *value,
55
                                    value_type new_value)
56
  {
57
    return __sync_lock_test_and_set(value, new_value);
58
  }
59
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
60
  inline bool compare_and_swap(volatile value_type *value,
910.5.2 by Monty Taylor
Applied atomic patch to current tree.
61
                                     value_type new_value,
62
                                     value_type comparand )
63
  {
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
64
    return __sync_bool_compare_and_swap(value, comparand, new_value);
910.5.2 by Monty Taylor
Applied atomic patch to current tree.
65
  }
66
67
  inline value_type fetch(const volatile value_type *value) const volatile
68
  {
1093.1.17 by Jay Pipes
Per IRC conversation with krow and mtaylor, reverted change in simple atomic fetch for GCC to previous call. Does not compile on ICC and added a note stating this.
69
    /* 
70
     * This is necessary to ensure memory barriers are respected when
71
     * simply returning the value pointed at.  However, this does not
72
     * compile on ICC.
73
     *
74
     * @todo
75
     *
76
     * Look at how to rewrite the below to something that ICC feels is
77
     * OK and yet respects memory barriers.
78
     */
1405.4.7 by Jay Pipes
* Fixes drizzled's atomics:
79
    return __sync_fetch_and_add(const_cast<value_type *>(value), 0);
910.5.2 by Monty Taylor
Applied atomic patch to current tree.
80
  }
81
82
  inline value_type store_with_release(volatile value_type *value,
83
                                       value_type new_value)
84
  {
85
    *value= new_value;
86
    return *value;
87
  }
88
89
}; /* gcc_traits */
90
91
92
} /* namespace internal */
968.2.3 by Monty Taylor
Replacd use of tbb:: namespace with drizzled::
93
} /* namespace drizzled */
910.5.2 by Monty Taylor
Applied atomic patch to current tree.
94