MySQL 8.0.40
Source Code Documentation
os0atomic.h
Go to the documentation of this file.
1/*****************************************************************************
2Copyright (c) 1995, 2024, Oracle and/or its affiliates.
3Copyright (c) 2008, Google Inc.
4
5Portions of this file contain modifications contributed and copyrighted by
6Google, Inc. Those modifications are gratefully acknowledged and are described
7briefly in the InnoDB documentation. The contributions by Google are
8incorporated with their permission, and subject to the conditions contained in
9the file COPYING.Google.
10
11This program is free software; you can redistribute it and/or modify it under
12the terms of the GNU General Public License, version 2.0, as published by the
13Free Software Foundation.
14
15This program is designed to work with certain software (including
16but not limited to OpenSSL) that is licensed under separate terms,
17as designated in a particular file or component or in included license
18documentation. The authors of MySQL hereby grant you an additional
19permission to link the program and your derivative works with the
20separately licensed software that they have either included with
21the program or referenced in the documentation.
22
23This program is distributed in the hope that it will be useful, but WITHOUT
24ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
25FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
26for more details.
27
28You should have received a copy of the GNU General Public License along with
29this program; if not, write to the Free Software Foundation, Inc.,
3051 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31
32*****************************************************************************/
33
34/** @file include/os0atomic.h
35 Macros for using atomics
36
37 Created 2012-09-23 Sunny Bains (Split from os0sync.h)
38 *******************************************************/
39
40#ifndef os0atomic_h
41#define os0atomic_h
42
43#include "univ.i"
44
45/** barrier definitions for memory ordering */
46#ifdef HAVE_IB_GCC_ATOMIC_THREAD_FENCE
47#define HAVE_MEMORY_BARRIER
48#define os_rmb __atomic_thread_fence(__ATOMIC_ACQUIRE)
49#define os_wmb __atomic_thread_fence(__ATOMIC_RELEASE)
50#define IB_MEMORY_BARRIER_STARTUP_MSG \
51 "GCC builtin __atomic_thread_fence() is used for memory barrier"
52
53#elif defined(HAVE_IB_GCC_SYNC_SYNCHRONISE)
54#define HAVE_MEMORY_BARRIER
55#define os_rmb __sync_synchronize()
56#define os_wmb __sync_synchronize()
57#define IB_MEMORY_BARRIER_STARTUP_MSG \
58 "GCC builtin __sync_synchronize() is used for memory barrier"
59
60#elif defined(HAVE_IB_MACHINE_BARRIER_SOLARIS)
61#define HAVE_MEMORY_BARRIER
62#include <mbarrier.h>
63#define os_rmb __machine_r_barrier()
64#define os_wmb __machine_w_barrier()
65#define IB_MEMORY_BARRIER_STARTUP_MSG \
66 "Solaris memory ordering functions are used for memory barrier"
67
68#elif defined(HAVE_WINDOWS_MM_FENCE) && defined(_WIN64)
69#define HAVE_MEMORY_BARRIER
70#include <mmintrin.h>
71#define os_rmb _mm_lfence()
72#define os_wmb _mm_sfence()
73#define IB_MEMORY_BARRIER_STARTUP_MSG \
74 "_mm_lfence() and _mm_sfence() are used for memory barrier"
75
76#else
77#define os_rmb
78#define os_wmb
79#define IB_MEMORY_BARRIER_STARTUP_MSG "Memory barrier is not used"
80#endif
81
82#endif /* !os0atomic_h */
Version control for database, common definitions, and include files.