641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
1 |
/*****************************************************************************
|
2 |
||
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
3 |
Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
|
4 |
Copyright (C) 2008, Google Inc.
|
|
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
5 |
|
6 |
Portions of this file contain modifications contributed and copyrighted by
|
|
7 |
Google, Inc. Those modifications are gratefully acknowledged and are described
|
|
8 |
briefly in the InnoDB documentation. The contributions by Google are
|
|
9 |
incorporated with their permission, and subject to the conditions contained in
|
|
10 |
the file COPYING.Google.
|
|
11 |
||
12 |
This program is free software; you can redistribute it and/or modify it under
|
|
13 |
the terms of the GNU General Public License as published by the Free Software
|
|
14 |
Foundation; version 2 of the License.
|
|
15 |
||
16 |
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
17 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
18 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
19 |
||
20 |
You should have received a copy of the GNU General Public License along with
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
21 |
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
|
22 |
St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
23 |
|
24 |
*****************************************************************************/
|
|
25 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
26 |
/**************************************************//**
|
27 |
@file include/os0sync.h
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
28 |
The interface to the operating system
|
29 |
synchronization primitives.
|
|
30 |
||
31 |
Created 9/6/1995 Heikki Tuuri
|
|
32 |
*******************************************************/
|
|
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
33 |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
34 |
#ifndef os0sync_h
|
35 |
#define os0sync_h
|
|
36 |
||
37 |
#include "univ.i" |
|
38 |
#include "ut0lst.h" |
|
39 |
||
40 |
#ifdef __WIN__
|
|
1819.9.44
by Calvin Sun, Stewart Smith
Merge Revision revid:calvin.sun@oracle.com-20100720204231-h3nw0d9q3h79krr4 from MySQL InnoDB |
41 |
/** Native event (slow)*/
|
42 |
typedef HANDLE os_native_event_t; |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
43 |
/** Native mutex */
|
1819.9.44
by Calvin Sun, Stewart Smith
Merge Revision revid:calvin.sun@oracle.com-20100720204231-h3nw0d9q3h79krr4 from MySQL InnoDB |
44 |
typedef CRITICAL_SECTION os_fast_mutex_t; |
45 |
/** Native condition variable. */
|
|
46 |
typedef CONDITION_VARIABLE os_cond_t; |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
47 |
#else
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
48 |
/** Native mutex */
|
1819.9.44
by Calvin Sun, Stewart Smith
Merge Revision revid:calvin.sun@oracle.com-20100720204231-h3nw0d9q3h79krr4 from MySQL InnoDB |
49 |
typedef pthread_mutex_t os_fast_mutex_t; |
50 |
/** Native condition variable */
|
|
51 |
typedef pthread_cond_t os_cond_t; |
|
52 |
#endif
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
53 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
54 |
/** Operating system event */
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
55 |
typedef struct os_event_struct os_event_struct_t; |
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
56 |
/** Operating system event handle */
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
57 |
typedef os_event_struct_t* os_event_t; |
58 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
59 |
/** An asynchronous signal sent between threads */
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
60 |
struct os_event_struct { |
1819.9.44
by Calvin Sun, Stewart Smith
Merge Revision revid:calvin.sun@oracle.com-20100720204231-h3nw0d9q3h79krr4 from MySQL InnoDB |
61 |
#ifdef __WIN__
|
62 |
HANDLE handle; /*!< kernel event object, slow, |
|
63 |
used on older Windows */
|
|
64 |
#endif
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
65 |
os_fast_mutex_t os_mutex; /*!< this mutex protects the next |
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
66 |
fields */
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
67 |
ibool is_set; /*!< this is TRUE when the event is |
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
68 |
in the signaled state, i.e., a thread
|
69 |
does not stop if it tries to wait for
|
|
70 |
this event */
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
71 |
ib_int64_t signal_count; /*!< this is incremented each time |
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
72 |
the event becomes signaled */
|
1819.9.44
by Calvin Sun, Stewart Smith
Merge Revision revid:calvin.sun@oracle.com-20100720204231-h3nw0d9q3h79krr4 from MySQL InnoDB |
73 |
os_cond_t cond_var; /*!< condition variable is used in |
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
74 |
waiting for the event */
|
75 |
UT_LIST_NODE_T(os_event_struct_t) os_event_list; |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
76 |
/*!< list of all created events */
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
77 |
};
|
78 |
||
1819.9.162
by Sunny Bains
Merge Revision revid:sunny.bains@oracle.com-20101014031202-36pv7sr5deftdrl4 from MySQL InnoDB |
79 |
/** Denotes an infinite delay for os_event_wait_time() */
|
80 |
#define OS_SYNC_INFINITE_TIME ULINT_UNDEFINED
|
|
81 |
||
82 |
/** Return value of os_event_wait_time() when the time is exceeded */
|
|
83 |
#define OS_SYNC_TIME_EXCEEDED 1
|
|
84 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
85 |
/** Operating system mutex */
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
86 |
typedef struct os_mutex_struct os_mutex_str_t; |
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
87 |
/** Operating system mutex handle */
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
88 |
typedef os_mutex_str_t* os_mutex_t; |
89 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
90 |
/** Mutex protecting counts and the event and OS 'slow' mutex lists */
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
91 |
extern os_mutex_t os_sync_mutex; |
92 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
93 |
/** This is incremented by 1 in os_thread_create and decremented by 1 in
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
94 |
os_thread_exit */
|
95 |
extern ulint os_thread_count; |
|
96 |
||
97 |
extern ulint os_event_count; |
|
98 |
extern ulint os_mutex_count; |
|
99 |
extern ulint os_fast_mutex_count; |
|
100 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
101 |
/*********************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
102 |
Initializes global event and OS 'slow' mutex lists. */
|
103 |
UNIV_INTERN
|
|
104 |
void
|
|
105 |
os_sync_init(void); |
|
106 |
/*==============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
107 |
/*********************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
108 |
Frees created events and OS 'slow' mutexes. */
|
109 |
UNIV_INTERN
|
|
110 |
void
|
|
111 |
os_sync_free(void); |
|
112 |
/*==============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
113 |
/*********************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
114 |
Creates an event semaphore, i.e., a semaphore which may just have two states:
|
115 |
signaled and nonsignaled. The created event is manual reset: it must be reset
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
116 |
explicitly by calling sync_os_reset_event.
|
117 |
@return the event handle */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
118 |
UNIV_INTERN
|
119 |
os_event_t
|
|
120 |
os_event_create( |
|
121 |
/*============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
122 |
const char* name); /*!< in: the name of the event, if NULL |
123 |
the event is created without a name */
|
|
124 |
/**********************************************************//**
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
125 |
Sets an event semaphore to the signaled state: lets waiting threads
|
126 |
proceed. */
|
|
127 |
UNIV_INTERN
|
|
128 |
void
|
|
129 |
os_event_set( |
|
130 |
/*=========*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
131 |
os_event_t event); /*!< in: event to set */ |
132 |
/**********************************************************//**
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
133 |
Resets an event semaphore to the nonsignaled state. Waiting threads will
|
134 |
stop to wait for the event.
|
|
135 |
The return value should be passed to os_even_wait_low() if it is desired
|
|
136 |
that this thread should not wait in case of an intervening call to
|
|
137 |
os_event_set() between this os_event_reset() and the
|
|
138 |
os_event_wait_low() call. See comments for os_event_wait_low(). */
|
|
139 |
UNIV_INTERN
|
|
140 |
ib_int64_t
|
|
141 |
os_event_reset( |
|
142 |
/*===========*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
143 |
os_event_t event); /*!< in: event to reset */ |
144 |
/**********************************************************//**
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
145 |
Frees an event object. */
|
146 |
UNIV_INTERN
|
|
147 |
void
|
|
148 |
os_event_free( |
|
149 |
/*==========*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
150 |
os_event_t event); /*!< in: event to free */ |
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
151 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
152 |
/**********************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
153 |
Waits for an event object until it is in the signaled state. If
|
154 |
srv_shutdown_state == SRV_SHUTDOWN_EXIT_THREADS this also exits the
|
|
155 |
waiting thread when the event becomes signaled (or immediately if the
|
|
156 |
event is already in the signaled state).
|
|
157 |
||
158 |
Typically, if the event has been signalled after the os_event_reset()
|
|
159 |
we'll return immediately because event->is_set == TRUE.
|
|
160 |
There are, however, situations (e.g.: sync_array code) where we may
|
|
161 |
lose this information. For example:
|
|
162 |
||
163 |
thread A calls os_event_reset()
|
|
164 |
thread B calls os_event_set() [event->is_set == TRUE]
|
|
165 |
thread C calls os_event_reset() [event->is_set == FALSE]
|
|
166 |
thread A calls os_event_wait() [infinite wait!]
|
|
167 |
thread C calls os_event_wait() [infinite wait!]
|
|
168 |
||
169 |
Where such a scenario is possible, to avoid infinite wait, the
|
|
170 |
value returned by os_event_reset() should be passed in as
|
|
171 |
reset_sig_count. */
|
|
172 |
UNIV_INTERN
|
|
173 |
void
|
|
174 |
os_event_wait_low( |
|
175 |
/*==============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
176 |
os_event_t event, /*!< in: event to wait */ |
177 |
ib_int64_t reset_sig_count);/*!< in: zero or the value |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
178 |
returned by previous call of
|
179 |
os_event_reset(). */
|
|
180 |
||
181 |
#define os_event_wait(event) os_event_wait_low(event, 0)
|
|
1819.9.162
by Sunny Bains
Merge Revision revid:sunny.bains@oracle.com-20101014031202-36pv7sr5deftdrl4 from MySQL InnoDB |
182 |
#define os_event_wait_time(e, t) os_event_wait_time_low(event, t, 0)
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
183 |
|
1819.9.162
by Sunny Bains
Merge Revision revid:sunny.bains@oracle.com-20101014031202-36pv7sr5deftdrl4 from MySQL InnoDB |
184 |
/**********************************************************//**
|
185 |
Waits for an event object until it is in the signaled state or
|
|
186 |
a timeout is exceeded. In Unix the timeout is always infinite.
|
|
187 |
@return 0 if success, OS_SYNC_TIME_EXCEEDED if timeout was exceeded */
|
|
188 |
UNIV_INTERN
|
|
189 |
ulint
|
|
190 |
os_event_wait_time_low( |
|
191 |
/*===================*/
|
|
192 |
os_event_t event, /*!< in: event to wait */ |
|
193 |
ulint time_in_usec, /*!< in: timeout in |
|
194 |
microseconds, or
|
|
195 |
OS_SYNC_INFINITE_TIME */
|
|
196 |
ib_int64_t reset_sig_count); /*!< in: zero or the value |
|
197 |
returned by previous call of
|
|
198 |
os_event_reset(). */
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
199 |
/*********************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
200 |
Creates an operating system mutex semaphore. Because these are slow, the
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
201 |
mutex semaphore of InnoDB itself (mutex_t) should be used where possible.
|
202 |
@return the mutex handle */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
203 |
UNIV_INTERN
|
204 |
os_mutex_t
|
|
1819.9.44
by Calvin Sun, Stewart Smith
Merge Revision revid:calvin.sun@oracle.com-20100720204231-h3nw0d9q3h79krr4 from MySQL InnoDB |
205 |
os_mutex_create(void); |
206 |
/*=================*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
207 |
/**********************************************************//**
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
208 |
Acquires ownership of a mutex semaphore. */
|
209 |
UNIV_INTERN
|
|
210 |
void
|
|
211 |
os_mutex_enter( |
|
212 |
/*===========*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
213 |
os_mutex_t mutex); /*!< in: mutex to acquire */ |
214 |
/**********************************************************//**
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
215 |
Releases ownership of a mutex. */
|
216 |
UNIV_INTERN
|
|
217 |
void
|
|
218 |
os_mutex_exit( |
|
219 |
/*==========*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
220 |
os_mutex_t mutex); /*!< in: mutex to release */ |
221 |
/**********************************************************//**
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
222 |
Frees an mutex object. */
|
223 |
UNIV_INTERN
|
|
224 |
void
|
|
225 |
os_mutex_free( |
|
226 |
/*==========*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
227 |
os_mutex_t mutex); /*!< in: mutex to free */ |
228 |
/**********************************************************//**
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
229 |
Acquires ownership of a fast mutex. Currently in Windows this is the same
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
230 |
as os_fast_mutex_lock!
|
231 |
@return 0 if success, != 0 if was reserved by another thread */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
232 |
UNIV_INLINE
|
233 |
ulint
|
|
234 |
os_fast_mutex_trylock( |
|
235 |
/*==================*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
236 |
os_fast_mutex_t* fast_mutex); /*!< in: mutex to acquire */ |
237 |
/**********************************************************//**
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
238 |
Releases ownership of a fast mutex. */
|
239 |
UNIV_INTERN
|
|
240 |
void
|
|
241 |
os_fast_mutex_unlock( |
|
242 |
/*=================*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
243 |
os_fast_mutex_t* fast_mutex); /*!< in: mutex to release */ |
244 |
/*********************************************************//**
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
245 |
Initializes an operating system fast mutex semaphore. */
|
246 |
UNIV_INTERN
|
|
247 |
void
|
|
248 |
os_fast_mutex_init( |
|
249 |
/*===============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
250 |
os_fast_mutex_t* fast_mutex); /*!< in: fast mutex */ |
251 |
/**********************************************************//**
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
252 |
Acquires ownership of a fast mutex. */
|
253 |
UNIV_INTERN
|
|
254 |
void
|
|
255 |
os_fast_mutex_lock( |
|
256 |
/*===============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
257 |
os_fast_mutex_t* fast_mutex); /*!< in: mutex to acquire */ |
258 |
/**********************************************************//**
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
259 |
Frees an mutex object. */
|
260 |
UNIV_INTERN
|
|
261 |
void
|
|
262 |
os_fast_mutex_free( |
|
263 |
/*===============*/
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
264 |
os_fast_mutex_t* fast_mutex); /*!< in: mutex to free */ |
265 |
||
266 |
/**********************************************************//**
|
|
267 |
Atomic compare-and-swap and increment for InnoDB. */
|
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
268 |
|
1819.5.56
by stewart at flamingspork
[patch 056/129] Merge patch for revision 1847 from InnoDB SVN: |
269 |
#if defined(HAVE_GCC_ATOMIC_BUILTINS)
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
270 |
|
271 |
#define HAVE_ATOMIC_BUILTINS
|
|
272 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
273 |
/**********************************************************//**
|
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
274 |
Returns true if swapped, ptr is pointer to target, old_val is value to
|
275 |
compare to, new_val is the value to swap in. */
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
276 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
277 |
# define os_compare_and_swap(ptr, old_val, new_val) \
|
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
278 |
__sync_bool_compare_and_swap(ptr, old_val, new_val)
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
279 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
280 |
# define os_compare_and_swap_ulint(ptr, old_val, new_val) \
|
281 |
os_compare_and_swap(ptr, old_val, new_val)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
282 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
283 |
# define os_compare_and_swap_lint(ptr, old_val, new_val) \
|
284 |
os_compare_and_swap(ptr, old_val, new_val)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
285 |
|
286 |
# ifdef HAVE_IB_ATOMIC_PTHREAD_T_GCC
|
|
287 |
# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
288 |
os_compare_and_swap(ptr, old_val, new_val)
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
289 |
# define INNODB_RW_LOCKS_USE_ATOMICS
|
1819.5.56
by stewart at flamingspork
[patch 056/129] Merge patch for revision 1847 from InnoDB SVN: |
290 |
# define IB_ATOMICS_STARTUP_MSG \
|
291 |
"Mutexes and rw_locks use GCC atomic builtins"
|
|
292 |
# else /* HAVE_IB_ATOMIC_PTHREAD_T_GCC */ |
|
293 |
# define IB_ATOMICS_STARTUP_MSG \
|
|
294 |
"Mutexes use GCC atomic builtins, rw_locks do not"
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
295 |
# endif /* HAVE_IB_ATOMIC_PTHREAD_T_GCC */ |
296 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
297 |
/**********************************************************//**
|
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
298 |
Returns the resulting value, ptr is pointer to target, amount is the
|
299 |
amount of increment. */
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
300 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
301 |
# define os_atomic_increment(ptr, amount) \
|
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
302 |
__sync_add_and_fetch(ptr, amount)
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
303 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
304 |
# define os_atomic_increment_lint(ptr, amount) \
|
305 |
os_atomic_increment(ptr, amount)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
306 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
307 |
# define os_atomic_increment_ulint(ptr, amount) \
|
308 |
os_atomic_increment(ptr, amount)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
309 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
310 |
/**********************************************************//**
|
311 |
Returns the old value of *ptr, atomically sets *ptr to new_val */
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
312 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
313 |
# define os_atomic_test_and_set_byte(ptr, new_val) \
|
1819.9.127
by Vasil Dimov
Merge Revision revid:vasil.dimov@oracle.com-20100930102618-s9f9ytbytr3eqw9h from MySQL InnoDB |
314 |
__sync_lock_test_and_set(ptr, (byte) new_val)
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
315 |
|
316 |
#elif defined(HAVE_SOLARIS_ATOMICS)
|
|
317 |
||
318 |
#define HAVE_ATOMIC_BUILTINS
|
|
319 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
320 |
/* If not compiling with GCC or GCC doesn't support the atomic
|
321 |
intrinsics and running on Solaris >= 10 use Solaris atomics */
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
322 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
323 |
#include <atomic.h> |
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
324 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
325 |
/**********************************************************//**
|
326 |
Returns true if swapped, ptr is pointer to target, old_val is value to
|
|
327 |
compare to, new_val is the value to swap in. */
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
328 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
329 |
# define os_compare_and_swap_ulint(ptr, old_val, new_val) \
|
330 |
(atomic_cas_ulong(ptr, old_val, new_val) == old_val)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
331 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
332 |
# define os_compare_and_swap_lint(ptr, old_val, new_val) \
|
333 |
((lint)atomic_cas_ulong((ulong_t*) ptr, old_val, new_val) == old_val)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
334 |
|
335 |
# ifdef HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS
|
|
336 |
# if SIZEOF_PTHREAD_T == 4
|
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
337 |
# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
|
338 |
((pthread_t)atomic_cas_32(ptr, old_val, new_val) == old_val)
|
|
339 |
# elif SIZEOF_PTHREAD_T == 8
|
|
340 |
# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
|
|
341 |
((pthread_t)atomic_cas_64(ptr, old_val, new_val) == old_val)
|
|
342 |
# else
|
|
343 |
# error "SIZEOF_PTHREAD_T != 4 or 8"
|
|
344 |
# endif /* SIZEOF_PTHREAD_T CHECK */ |
|
1819.5.56
by stewart at flamingspork
[patch 056/129] Merge patch for revision 1847 from InnoDB SVN: |
345 |
# define INNODB_RW_LOCKS_USE_ATOMICS
|
346 |
# define IB_ATOMICS_STARTUP_MSG \
|
|
347 |
"Mutexes and rw_locks use Solaris atomic functions"
|
|
348 |
# else /* HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS */ |
|
349 |
# define IB_ATOMICS_STARTUP_MSG \
|
|
350 |
"Mutexes use Solaris atomic functions, rw_locks do not"
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
351 |
# endif /* HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS */ |
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
352 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
353 |
/**********************************************************//**
|
354 |
Returns the resulting value, ptr is pointer to target, amount is the
|
|
355 |
amount of increment. */
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
356 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
357 |
# define os_atomic_increment_lint(ptr, amount) \
|
358 |
atomic_add_long_nv((ulong_t*) ptr, amount)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
359 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
360 |
# define os_atomic_increment_ulint(ptr, amount) \
|
361 |
atomic_add_long_nv(ptr, amount)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
362 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
363 |
/**********************************************************//**
|
364 |
Returns the old value of *ptr, atomically sets *ptr to new_val */
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
365 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
366 |
# define os_atomic_test_and_set_byte(ptr, new_val) \
|
367 |
atomic_swap_uchar(ptr, new_val)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
368 |
|
369 |
#elif defined(HAVE_WINDOWS_ATOMICS)
|
|
370 |
||
371 |
#define HAVE_ATOMIC_BUILTINS
|
|
372 |
||
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
373 |
/* On Windows, use Windows atomics / interlocked */
|
374 |
# ifdef _WIN64
|
|
375 |
# define win_cmp_and_xchg InterlockedCompareExchange64
|
|
376 |
# define win_xchg_and_add InterlockedExchangeAdd64
|
|
377 |
# else /* _WIN64 */ |
|
378 |
# define win_cmp_and_xchg InterlockedCompareExchange
|
|
379 |
# define win_xchg_and_add InterlockedExchangeAdd
|
|
380 |
# endif
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
381 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
382 |
/**********************************************************//**
|
383 |
Returns true if swapped, ptr is pointer to target, old_val is value to
|
|
384 |
compare to, new_val is the value to swap in. */
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
385 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
386 |
# define os_compare_and_swap_ulint(ptr, old_val, new_val) \
|
387 |
(win_cmp_and_xchg(ptr, new_val, old_val) == old_val)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
388 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
389 |
# define os_compare_and_swap_lint(ptr, old_val, new_val) \
|
390 |
(win_cmp_and_xchg(ptr, new_val, old_val) == old_val)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
391 |
|
1819.5.55
by stewart at flamingspork
[patch 055/129] Merge patch for revision 1846 from InnoDB SVN: |
392 |
/* windows thread objects can always be passed to windows atomic functions */
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
393 |
# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
394 |
(InterlockedCompareExchange(ptr, new_val, old_val) == old_val)
|
1819.5.56
by stewart at flamingspork
[patch 056/129] Merge patch for revision 1847 from InnoDB SVN: |
395 |
# define INNODB_RW_LOCKS_USE_ATOMICS
|
396 |
# define IB_ATOMICS_STARTUP_MSG \
|
|
397 |
"Mutexes and rw_locks use Windows interlocked functions"
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
398 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
399 |
/**********************************************************//**
|
400 |
Returns the resulting value, ptr is pointer to target, amount is the
|
|
401 |
amount of increment. */
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
402 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
403 |
# define os_atomic_increment_lint(ptr, amount) \
|
404 |
(win_xchg_and_add(ptr, amount) + amount)
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
405 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
406 |
# define os_atomic_increment_ulint(ptr, amount) \
|
407 |
((ulint) (win_xchg_and_add(ptr, amount) + amount))
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
408 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
409 |
/**********************************************************//**
|
410 |
Returns the old value of *ptr, atomically sets *ptr to new_val.
|
|
411 |
InterlockedExchange() operates on LONG, and the LONG will be
|
|
412 |
clobbered */
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
413 |
|
641.2.3
by Monty Taylor
InnoDB Plugin 1.0.4 |
414 |
# define os_atomic_test_and_set_byte(ptr, new_val) \
|
415 |
((byte) InterlockedExchange(ptr, new_val))
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
416 |
|
1819.5.56
by stewart at flamingspork
[patch 056/129] Merge patch for revision 1847 from InnoDB SVN: |
417 |
#else
|
418 |
# define IB_ATOMICS_STARTUP_MSG \
|
|
419 |
"Mutexes and rw_locks use InnoDB's own implementation"
|
|
1819.5.53
by stewart at flamingspork
[patch 053/129] Merge patch for revision 1843 from InnoDB SVN: |
420 |
#endif
|
641.2.2
by Monty Taylor
InnoDB Plugin 1.0.3 |
421 |
|
641.1.2
by Monty Taylor
Imported 1.0.1 with clean - with no changes. |
422 |
#ifndef UNIV_NONINL
|
423 |
#include "os0sync.ic" |
|
424 |
#endif
|
|
425 |
||
426 |
#endif
|