~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to include/my_atomic.h

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2006 MySQL AB
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
 
 
16
 
#ifndef my_atomic_rwlock_init
17
 
 
18
 
#define intptr         void *
19
 
 
20
 
#ifndef MY_ATOMIC_MODE_RWLOCKS
21
 
#include "atomic/nolock.h"
22
 
#endif
23
 
 
24
 
#ifndef make_atomic_cas_body
25
 
#include "atomic/rwlock.h"
26
 
#endif
27
 
 
28
 
#ifndef make_atomic_add_body
29
 
#define make_atomic_add_body(S)                                 \
30
 
  int ## S tmp=*a;                                              \
31
 
  while (!my_atomic_cas ## S(a, &tmp, tmp+v));                  \
32
 
  v=tmp;
33
 
#endif
34
 
 
35
 
#ifdef HAVE_INLINE
36
 
 
37
 
#define make_atomic_add(S)                                      \
38
 
STATIC_INLINE int ## S my_atomic_add ## S(                      \
39
 
                        int ## S volatile *a, int ## S v)       \
40
 
{                                                               \
41
 
  make_atomic_add_body(S);                                      \
42
 
  return v;                                                     \
43
 
}
44
 
 
45
 
#define make_atomic_swap(S)                                     \
46
 
STATIC_INLINE int ## S my_atomic_swap ## S(                     \
47
 
                         int ## S volatile *a, int ## S v)      \
48
 
{                                                               \
49
 
  make_atomic_swap_body(S);                                     \
50
 
  return v;                                                     \
51
 
}
52
 
 
53
 
#define make_atomic_cas(S)                                      \
54
 
STATIC_INLINE int my_atomic_cas ## S(int ## S volatile *a,      \
55
 
                            int ## S *cmp, int ## S set)        \
56
 
{                                                               \
57
 
  int8 ret;                                                     \
58
 
  make_atomic_cas_body(S);                                      \
59
 
  return ret;                                                   \
60
 
}
61
 
 
62
 
#define make_atomic_load(S)                                     \
63
 
STATIC_INLINE int ## S my_atomic_load ## S(int ## S volatile *a) \
64
 
{                                                               \
65
 
  int ## S ret;                                         \
66
 
  make_atomic_load_body(S);                                     \
67
 
  return ret;                                                   \
68
 
}
69
 
 
70
 
#define make_atomic_store(S)                                    \
71
 
STATIC_INLINE void my_atomic_store ## S(                        \
72
 
                     int ## S volatile *a, int ## S v)  \
73
 
{                                                               \
74
 
  make_atomic_store_body(S);                                    \
75
 
}
76
 
 
77
 
#else /* no inline functions */
78
 
 
79
 
#define make_atomic_add(S)                                      \
80
 
extern int ## S my_atomic_add ## S(int ## S volatile *a, int ## S v);
81
 
 
82
 
#define make_atomic_swap(S)                                     \
83
 
extern int ## S my_atomic_swap ## S(int ## S volatile *a, int ## S v);
84
 
 
85
 
#define make_atomic_cas(S)                                      \
86
 
extern int my_atomic_cas ## S(int ## S volatile *a, int ## S *cmp, int ## S set);
87
 
 
88
 
#define make_atomic_load(S)                                     \
89
 
extern int ## S my_atomic_load ## S(int ## S volatile *a);
90
 
 
91
 
#define make_atomic_store(S)                                    \
92
 
extern void my_atomic_store ## S(int ## S volatile *a, int ## S v);
93
 
 
94
 
#endif
95
 
 
96
 
make_atomic_cas( 8)
97
 
make_atomic_cas(16)
98
 
make_atomic_cas(32)
99
 
make_atomic_cas(ptr)
100
 
 
101
 
make_atomic_add( 8)
102
 
make_atomic_add(16)
103
 
make_atomic_add(32)
104
 
 
105
 
make_atomic_load( 8)
106
 
make_atomic_load(16)
107
 
make_atomic_load(32)
108
 
make_atomic_load(ptr)
109
 
 
110
 
make_atomic_store( 8)
111
 
make_atomic_store(16)
112
 
make_atomic_store(32)
113
 
make_atomic_store(ptr)
114
 
 
115
 
make_atomic_swap( 8)
116
 
make_atomic_swap(16)
117
 
make_atomic_swap(32)
118
 
make_atomic_swap(ptr)
119
 
 
120
 
#undef make_atomic_add
121
 
#undef make_atomic_cas
122
 
#undef make_atomic_load
123
 
#undef make_atomic_store
124
 
#undef make_atomic_swap
125
 
#undef make_atomic_add_body
126
 
#undef make_atomic_cas_body
127
 
#undef make_atomic_load_body
128
 
#undef make_atomic_store_body
129
 
#undef make_atomic_swap_body
130
 
#undef intptr
131
 
 
132
 
#ifdef _atomic_h_cleanup_
133
 
#include _atomic_h_cleanup_
134
 
#undef _atomic_h_cleanup_
135
 
#endif
136
 
 
137
 
#define MY_ATOMIC_OK       0
138
 
#define MY_ATOMIC_NOT_1CPU 1
139
 
extern int my_atomic_initialize();
140
 
 
141
 
#endif
142