~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/atomic/sun_studio.h

  • Committer: Monty Taylor
  • Date: 2009-03-04 02:48:12 UTC
  • mto: (917.1.2 mordred)
  • mto: This revision was merged to the branch mainline in revision 918.
  • Revision ID: mordred@inaugust.com-20090304024812-5wb6wpye5c1iitbq
Applied atomic patch to current tree.

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_SUN_STUDIO_H
 
21
#define DRIZZLED_ATOMIC_SUN_STUDIO_H
 
22
 
 
23
#define _KERNEL
 
24
#include <atomic.h>
 
25
#undef _KERNEL
 
26
 
 
27
inline uint8_t __sync_add_and_fetch(volatile uint8_t* ptr, uint8_t val)
 
28
{
 
29
  (val == 1) ? atomic_inc_8(ptr) : atomic_add_8(ptr, (int8_t)val);
 
30
  return *ptr;
 
31
}
 
32
 
 
33
inline uint16_t __sync_add_and_fetch(volatile uint16_t* ptr, uint16_t val)
 
34
{
 
35
  (val == 1) ? atomic_inc_16(ptr) : atomic_add_16(ptr, (int16_t)val);
 
36
  return *ptr;
 
37
}
 
38
 
 
39
inline uint32_t __sync_add_and_fetch(volatile uint32_t* ptr, uint32_t val)
 
40
{
 
41
  (val == 1) ? atomic_inc_32(ptr) : atomic_add_32(ptr, (int32_t)val);
 
42
  return *ptr;
 
43
}
 
44
 
 
45
# if defined(_KERNEL) || defined(_INT64_TYPE)
 
46
inline uint64_t __sync_add_and_fetch(volatile uint64_t* ptr, uint64_t val)
 
47
{
 
48
  (val == 1) ? atomic_inc_64(ptr) : atomic_add_64(ptr, (int64_t)val);
 
49
  return *ptr;
 
50
}
 
51
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
 
52
 
 
53
 
 
54
inline uint8_t __sync_sub_and_fetch(volatile uint8_t* ptr, uint8_t val)
 
55
{
 
56
  (val == 1) ? atomic_dec_8(ptr) : atomic_add_8(ptr, 0-(int8_t)val);
 
57
  return *ptr;
 
58
}
 
59
 
 
60
inline uint16_t __sync_sub_and_fetch(volatile uint16_t* ptr, uint16_t val)
 
61
{
 
62
  (val == 1) ? atomic_dec_16(ptr) : atomic_add_16(ptr, 0-(int16_t)val);
 
63
  return *ptr;
 
64
}
 
65
 
 
66
inline uint32_t __sync_sub_and_fetch(volatile uint32_t* ptr, uint32_t val)
 
67
{
 
68
  (val == 1) ? atomic_dec_32(ptr) : atomic_add_32(ptr, 0-(int32_t)val);
 
69
  return *ptr;
 
70
}
 
71
 
 
72
# if defined(_KERNEL) || defined(_INT64_TYPE)
 
73
inline uint64_t __sync_sub_and_fetch(volatile uint64_t* ptr, uint64_t val)
 
74
{
 
75
  (val == 1) ? atomic_dec_64(ptr) : atomic_add_64(ptr, 0-(int64_t)val);
 
76
  return *ptr;
 
77
}
 
78
# endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
 
79
 
 
80
 
 
81
inline uint8_t __sync_lock_test_and_set(volatile uint8_t* ptr, uint8_t val)
 
82
{
 
83
  atomic_swap_8(ptr, val);
 
84
  return *ptr;
 
85
}
 
86
 
 
87
inline uint16_t __sync_lock_test_and_set(volatile uint16_t* ptr, uint16_t val)
 
88
{
 
89
  atomic_swap_16(ptr, val);
 
90
  return *ptr;
 
91
}
 
92
 
 
93
inline uint32_t __sync_lock_test_and_set(volatile uint32_t* ptr, uint32_t val)
 
94
{
 
95
  atomic_swap_32(ptr, val);
 
96
  return *ptr;
 
97
}
 
98
 
 
99
# if defined(_KERNEL) || defined(_INT64_TYPE)
 
100
inline uint64_t __sync_lock_test_and_set(volatile uint64_t* ptr, uint64_t val)
 
101
{
 
102
  atomic_swap_64(ptr, val);
 
103
  return *ptr;
 
104
}
 
105
#endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
 
106
 
 
107
inline uint8_t __sync_val_compare_and_swap(volatile uint8_t* ptr,
 
108
                                           uint8_t old_val, uint8_t val)
 
109
{
 
110
  atomic_cas_8(ptr, old_val, val);
 
111
  return *ptr;
 
112
}
 
113
 
 
114
inline uint16_t __sync_val_compare_and_swap(volatile uint16_t* ptr,
 
115
                                            uint16_t old_val, uint16_t val)
 
116
{
 
117
  atomic_cas_16(ptr, old_val, val);
 
118
  return *ptr;
 
119
}
 
120
 
 
121
inline uint32_t __sync_val_compare_and_swap(volatile uint32_t* ptr,
 
122
                                            uint32_t old_val, uint32_t val)
 
123
{
 
124
  atomic_cas_32(ptr, old_val, val);
 
125
  return *ptr;
 
126
}
 
127
 
 
128
# if defined(_KERNEL) || defined(_INT64_TYPE)
 
129
inline uint64_t __sync_val_compare_and_swap(volatile uint64_t* ptr,
 
130
                                            uint64_t old_val, uint64_t val)
 
131
{
 
132
  atomic_cas_64(ptr, old_val, val);
 
133
  return *ptr;
 
134
}
 
135
#endif /* defined(_KERNEL) || defined(_INT64_TYPE) */
 
136
 
 
137
 
 
138
#endif /* DRIZZLED_ATOMIC_SOLARIS_H */