MySQL 9.0.0
Source Code Documentation
my_atomic.h
Go to the documentation of this file.
1#ifndef MY_ATOMIC_INCLUDED
2#define MY_ATOMIC_INCLUDED
3
4/* Copyright (c) 2006, 2024, Oracle and/or its affiliates.
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, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27/**
28 @file include/my_atomic.h
29*/
30
31#if defined(_MSC_VER)
32
33#include <windows.h>
34
35/*
36 my_yield_processor (equivalent of x86 PAUSE instruction) should be used
37 to improve performance on hyperthreaded CPUs. Intel recommends to use it in
38 spin loops also on non-HT machines to reduce power consumption (see e.g
39 http://softwarecommunity.intel.com/articles/eng/2004.htm)
40
41 Running benchmarks for spinlocks implemented with InterlockedCompareExchange
42 and YieldProcessor shows that much better performance is achieved by calling
43 YieldProcessor in a loop - that is, yielding longer. On Intel boxes setting
44 loop count in the range 200-300 brought best results.
45 */
46#define YIELD_LOOPS 200
47
48static inline int my_yield_processor() {
49 int i;
50 for (i = 0; i < YIELD_LOOPS; i++) {
51 YieldProcessor();
52 }
53 return 1;
54}
55
56#define LF_BACKOFF my_yield_processor()
57
58#else // !defined(_MSC_VER)
59
60#define LF_BACKOFF (1)
61
62#endif
63
64#endif /* MY_ATOMIC_INCLUDED */