drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
os0sync.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
4Copyright (C) 2008, Google Inc.
5
6Portions of this file contain modifications contributed and copyrighted by
7Google, Inc. Those modifications are gratefully acknowledged and are described
8briefly in the InnoDB documentation. The contributions by Google are
9incorporated with their permission, and subject to the conditions contained in
10the file COPYING.Google.
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; version 2 of the License.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License along with
21this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22St, Fifth Floor, Boston, MA 02110-1301 USA
23
24*****************************************************************************/
25
26/**************************************************/
33
34#pragma once
35#ifndef os0sync_h
36#define os0sync_h
37
38#include "univ.i"
39#include "ut0lst.h"
40
41#ifdef __WIN__
43typedef HANDLE os_native_event_t;
45typedef CRITICAL_SECTION os_fast_mutex_t;
47typedef CONDITION_VARIABLE os_cond_t;
48#else
50typedef pthread_mutex_t os_fast_mutex_t;
52typedef pthread_cond_t os_cond_t;
53#endif
54
59
62#ifdef __WIN__
63 HANDLE handle;
65#endif
68 ibool is_set;
72 ib_int64_t signal_count;
78};
79
81#define OS_SYNC_INFINITE_TIME ULINT_UNDEFINED
82
84#define OS_SYNC_TIME_EXCEEDED 1
85
90
93
96extern ulint os_thread_count;
97
98extern ulint os_event_count;
99extern ulint os_mutex_count;
100extern ulint os_fast_mutex_count;
101
102/*********************************************************/
104UNIV_INTERN
105void
106os_sync_init(void);
107/*==============*/
108/*********************************************************/
110UNIV_INTERN
111void
112os_sync_free(void);
113/*==============*/
114/*********************************************************/
119UNIV_INTERN
122/*============*/
123 const char* name);
125/**********************************************************/
128UNIV_INTERN
129void
131/*=========*/
133/**********************************************************/
140UNIV_INTERN
141ib_int64_t
143/*===========*/
145/**********************************************************/
147UNIV_INTERN
148void
150/*==========*/
152
153/**********************************************************/
173UNIV_INTERN
174void
176/*==============*/
178 ib_int64_t reset_sig_count);
181
182#define os_event_wait(event) os_event_wait_low(event, 0)
183#define os_event_wait_time(e, t) os_event_wait_time_low(event, t, 0)
184
185/**********************************************************/
189UNIV_INTERN
190ulint
192/*===================*/
194 ulint time_in_usec,
197 ib_int64_t reset_sig_count);
200/*********************************************************/
204UNIV_INTERN
206os_mutex_create(void);
207/*=================*/
208/**********************************************************/
210UNIV_INTERN
211void
213/*===========*/
214 os_mutex_t mutex);
215/**********************************************************/
217UNIV_INTERN
218void
220/*==========*/
221 os_mutex_t mutex);
222/**********************************************************/
224UNIV_INTERN
225void
227/*==========*/
228 os_mutex_t mutex);
229/**********************************************************/
233UNIV_INLINE
234ulint
236/*==================*/
237 os_fast_mutex_t* fast_mutex);
238/**********************************************************/
240UNIV_INTERN
241void
243/*=================*/
244 os_fast_mutex_t* fast_mutex);
245/*********************************************************/
247UNIV_INTERN
248void
250/*===============*/
251 os_fast_mutex_t* fast_mutex);
252/**********************************************************/
254UNIV_INTERN
255void
257/*===============*/
258 os_fast_mutex_t* fast_mutex);
259/**********************************************************/
261UNIV_INTERN
262void
264/*===============*/
265 os_fast_mutex_t* fast_mutex);
266
267/**********************************************************/
269
270#if defined(HAVE_GCC_ATOMIC_BUILTINS)
271
272#define HAVE_ATOMIC_BUILTINS
273
274/**********************************************************/
277
278# define os_compare_and_swap(ptr, old_val, new_val) \
279 __sync_bool_compare_and_swap(ptr, old_val, new_val)
280
281# define os_compare_and_swap_ulint(ptr, old_val, new_val) \
282 os_compare_and_swap(ptr, old_val, new_val)
283
284# define os_compare_and_swap_lint(ptr, old_val, new_val) \
285 os_compare_and_swap(ptr, old_val, new_val)
286
287# ifdef HAVE_IB_ATOMIC_PTHREAD_T_GCC
288# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
289 os_compare_and_swap(ptr, old_val, new_val)
290# define INNODB_RW_LOCKS_USE_ATOMICS
291# define IB_ATOMICS_STARTUP_MSG \
292 "Mutexes and rw_locks use GCC atomic builtins"
293# else /* HAVE_IB_ATOMIC_PTHREAD_T_GCC */
294# define IB_ATOMICS_STARTUP_MSG \
295 "Mutexes use GCC atomic builtins, rw_locks do not"
296# endif /* HAVE_IB_ATOMIC_PTHREAD_T_GCC */
297
298/**********************************************************/
301
302# define os_atomic_increment(ptr, amount) \
303 __sync_add_and_fetch(ptr, amount)
304
305# define os_atomic_increment_lint(ptr, amount) \
306 os_atomic_increment(ptr, amount)
307
308# define os_atomic_increment_ulint(ptr, amount) \
309 os_atomic_increment(ptr, amount)
310
311/**********************************************************/
313
314# define os_atomic_test_and_set_byte(ptr, new_val) \
315 __sync_lock_test_and_set(ptr, (byte) new_val)
316
317#elif defined(HAVE_SOLARIS_ATOMICS)
318
319#define HAVE_ATOMIC_BUILTINS
320
321/* If not compiling with GCC or GCC doesn't support the atomic
322intrinsics and running on Solaris >= 10 use Solaris atomics */
323
324#include <atomic.h>
325
326/**********************************************************/
329
330# define os_compare_and_swap_ulint(ptr, old_val, new_val) \
331 (atomic_cas_ulong(ptr, old_val, new_val) == old_val)
332
333# define os_compare_and_swap_lint(ptr, old_val, new_val) \
334 ((lint)atomic_cas_ulong((ulong_t*) ptr, old_val, new_val) == old_val)
335
336# ifdef HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS
337# if SIZEOF_PTHREAD_T == 4
338# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
339 ((pthread_t)atomic_cas_32(ptr, old_val, new_val) == old_val)
340# elif SIZEOF_PTHREAD_T == 8
341# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
342 ((pthread_t)atomic_cas_64(ptr, old_val, new_val) == old_val)
343# else
344# error "SIZEOF_PTHREAD_T != 4 or 8"
345# endif /* SIZEOF_PTHREAD_T CHECK */
346# define INNODB_RW_LOCKS_USE_ATOMICS
347# define IB_ATOMICS_STARTUP_MSG \
348 "Mutexes and rw_locks use Solaris atomic functions"
349# else /* HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS */
350# define IB_ATOMICS_STARTUP_MSG \
351 "Mutexes use Solaris atomic functions, rw_locks do not"
352# endif /* HAVE_IB_ATOMIC_PTHREAD_T_SOLARIS */
353
354/**********************************************************/
357
358# define os_atomic_increment_lint(ptr, amount) \
359 atomic_add_long_nv((ulong_t*) ptr, amount)
360
361# define os_atomic_increment_ulint(ptr, amount) \
362 atomic_add_long_nv(ptr, amount)
363
364/**********************************************************/
366
367# define os_atomic_test_and_set_byte(ptr, new_val) \
368 atomic_swap_uchar(ptr, new_val)
369
370#elif defined(HAVE_WINDOWS_ATOMICS)
371
372#define HAVE_ATOMIC_BUILTINS
373
374/* On Windows, use Windows atomics / interlocked */
375# ifdef _WIN64
376# define win_cmp_and_xchg InterlockedCompareExchange64
377# define win_xchg_and_add InterlockedExchangeAdd64
378# else /* _WIN64 */
379# define win_cmp_and_xchg InterlockedCompareExchange
380# define win_xchg_and_add InterlockedExchangeAdd
381# endif
382
383/**********************************************************/
386
387# define os_compare_and_swap_ulint(ptr, old_val, new_val) \
388 (win_cmp_and_xchg(ptr, new_val, old_val) == old_val)
389
390# define os_compare_and_swap_lint(ptr, old_val, new_val) \
391 (win_cmp_and_xchg(ptr, new_val, old_val) == old_val)
392
393/* windows thread objects can always be passed to windows atomic functions */
394# define os_compare_and_swap_thread_id(ptr, old_val, new_val) \
395 (InterlockedCompareExchange(ptr, new_val, old_val) == old_val)
396# define INNODB_RW_LOCKS_USE_ATOMICS
397# define IB_ATOMICS_STARTUP_MSG \
398 "Mutexes and rw_locks use Windows interlocked functions"
399
400/**********************************************************/
403
404# define os_atomic_increment_lint(ptr, amount) \
405 (win_xchg_and_add(ptr, amount) + amount)
406
407# define os_atomic_increment_ulint(ptr, amount) \
408 ((ulint) (win_xchg_and_add(ptr, amount) + amount))
409
410/**********************************************************/
414
415# define os_atomic_test_and_set_byte(ptr, new_val) \
416 ((byte) InterlockedExchange(ptr, new_val))
417
418#else
419# define IB_ATOMICS_STARTUP_MSG \
420 "Mutexes and rw_locks use InnoDB's own implementation"
421#endif
422
423#ifndef UNIV_NONINL
424#include "os0sync.ic"
425#endif
426
427#endif
UNIV_INTERN void os_event_wait_low(os_event_t event, ib_int64_t reset_sig_count)
Definition os0sync.cc:586
os_mutex_t os_sync_mutex
Definition os0sync.cc:59
UNIV_INTERN ib_int64_t os_event_reset(os_event_t event)
Definition os0sync.cc:472
UNIV_INTERN void os_mutex_enter(os_mutex_t mutex)
Definition os0sync.cc:809
UNIV_INTERN void os_fast_mutex_free(os_fast_mutex_t *fast_mutex)
Definition os0sync.cc:930
UNIV_INTERN ulint os_event_wait_time_low(os_event_t event, ulint time_in_usec, ib_int64_t reset_sig_count)
Definition os0sync.cc:652
UNIV_INTERN os_event_t os_event_create(const char *name)
Definition os0sync.cc:365
UNIV_INLINE ulint os_fast_mutex_trylock(os_fast_mutex_t *fast_mutex)
UNIV_INTERN void os_fast_mutex_lock(os_fast_mutex_t *fast_mutex)
Definition os0sync.cc:900
pthread_cond_t os_cond_t
Definition os0sync.h:52
UNIV_INTERN void os_sync_free(void)
Definition os0sync.cc:325
UNIV_INTERN void os_event_set(os_event_t event)
Definition os0sync.cc:434
UNIV_INTERN void os_fast_mutex_init(os_fast_mutex_t *fast_mutex)
Definition os0sync.cc:871
UNIV_INTERN void os_event_free(os_event_t event)
Definition os0sync.cc:535
struct os_mutex_struct os_mutex_str_t
Definition os0sync.h:87
os_event_struct_t * os_event_t
Definition os0sync.h:58
UNIV_INTERN os_mutex_t os_mutex_create(void)
Definition os0sync.cc:774
os_mutex_str_t * os_mutex_t
Definition os0sync.h:89
UNIV_INTERN void os_mutex_exit(os_mutex_t mutex)
Definition os0sync.cc:824
UNIV_INTERN void os_sync_init(void)
Definition os0sync.cc:304
UNIV_INTERN void os_fast_mutex_unlock(os_fast_mutex_t *fast_mutex)
Definition os0sync.cc:915
ulint os_thread_count
Definition os0sync.cc:67
pthread_mutex_t os_fast_mutex_t
Definition os0sync.h:50
struct os_event_struct os_event_struct_t
Definition os0sync.h:56
UNIV_INTERN void os_mutex_free(os_mutex_t mutex)
Definition os0sync.cc:840
UT_LIST_NODE_T(os_event_struct_t) os_event_list
os_cond_t cond_var
Definition os0sync.h:74
ib_int64_t signal_count
Definition os0sync.h:72
os_fast_mutex_t os_mutex
Definition os0sync.h:66
os_event_t event
Definition os0sync.cc:46