~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/atomic/gcc_traits.h

  • Committer: Monty Taylor
  • Date: 2009-01-09 07:02:24 UTC
  • mto: (779.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 784.
  • Revision ID: mordred@inaugust.com-20090109070224-prwl5p52mfql3zfw
Split out readline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
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
 
#ifndef DRIZZLED_ATOMIC_GCC_TRAITS_H
21
 
#define DRIZZLED_ATOMIC_GCC_TRAITS_H
22
 
 
23
 
namespace tbb {
24
 
namespace internal {
25
 
 
26
 
template<typename T, typename D>
27
 
class gcc_traits
28
 
{
29
 
 
30
 
public:
31
 
  typedef T value_type;
32
 
 
33
 
  gcc_traits() {}
34
 
 
35
 
  /* YES. I know these are semantically backwards...
36
 
   * so... TODO: Ensure we're doing the "right" thing here
37
 
   */
38
 
  inline value_type fetch_and_add(volatile value_type *value, D addend )
39
 
  {
40
 
    return __sync_add_and_fetch(value, addend);
41
 
  }
42
 
 
43
 
  inline value_type fetch_and_increment(volatile value_type *value)
44
 
  {
45
 
    return __sync_add_and_fetch(value, 1);
46
 
  }
47
 
 
48
 
  inline value_type fetch_and_decrement(volatile value_type *value)
49
 
  {
50
 
    return __sync_sub_and_fetch(value, 1);
51
 
  }
52
 
 
53
 
  inline value_type fetch_and_store(volatile value_type *value,
54
 
                                    value_type new_value)
55
 
  {
56
 
    /* TODO: Is this the right one? */
57
 
    return __sync_lock_test_and_set(value, new_value);
58
 
  }
59
 
 
60
 
  inline value_type compare_and_swap(volatile value_type *value,
61
 
                                     value_type new_value,
62
 
                                     value_type comparand )
63
 
  {
64
 
    return __sync_val_compare_and_swap(value, comparand, new_value);
65
 
  }
66
 
 
67
 
  inline value_type fetch(const volatile value_type *value) const volatile
68
 
  {
69
 
    return __sync_add_and_fetch(const_cast<value_type *>(value), 0);
70
 
  }
71
 
 
72
 
  inline value_type store_with_release(volatile value_type *value,
73
 
                                       value_type new_value)
74
 
  {
75
 
    *value= new_value;
76
 
    return *value;
77
 
  }
78
 
 
79
 
}; /* gcc_traits */
80
 
 
81
 
 
82
 
} /* namespace internal */
83
 
} /* namespace tbb */
84
 
 
85
 
#endif /* DRIZZLED_ATOMIC_GCC_TRAITS_H */