MySQL 9.3.0
Source Code Documentation
atomic_flag.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, 2025, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_JIT_EXECUTOR_UTILS_ATOMIC_FLAG_H_
27#define ROUTER_SRC_JIT_EXECUTOR_UTILS_ATOMIC_FLAG_H_
28
29#include <atomic>
30
31namespace shcore {
32
33// We cannot simply use std::atomic_flag, because GCC10 does not have
34// std::atomic_flag::test().
35#if defined(__cpp_lib_atomic_flag_test)
36
37class atomic_flag : public std::atomic_flag {
38 public:
39 using std::atomic_flag::atomic_flag;
40
41 private:
42 using std::atomic_flag::notify_all;
43 using std::atomic_flag::notify_one;
45};
46
47#elif 2 == ATOMIC_BOOL_LOCK_FREE // std::atomic<bool> is always lock-free
48
49/**
50 * A lock-free atomic boolean type.
51 */
52class atomic_flag {
53 public:
54 constexpr atomic_flag() noexcept = default;
55
56 atomic_flag(const atomic_flag &) = delete;
57
58 atomic_flag &operator=(const atomic_flag &) = delete;
59 atomic_flag &operator=(const atomic_flag &) volatile = delete;
60
61 ~atomic_flag() noexcept = default;
62
63 inline void clear(
64 std::memory_order order = std::memory_order_seq_cst) volatile noexcept {
65 m_flag.store(false, order);
66 }
67
68 inline void clear(
69 std::memory_order order = std::memory_order_seq_cst) noexcept {
70 m_flag.store(false, order);
71 }
72
73 inline bool test_and_set(
74 std::memory_order order = std::memory_order_seq_cst) volatile noexcept {
75 return m_flag.exchange(true, order);
76 }
77
78 inline bool test_and_set(
79 std::memory_order order = std::memory_order_seq_cst) noexcept {
80 return m_flag.exchange(true, order);
81 }
82
83 inline bool test(std::memory_order order = std::memory_order_seq_cst) const
84 volatile noexcept {
85 return m_flag.load(order);
86 }
87
88 inline bool test(
89 std::memory_order order = std::memory_order_seq_cst) const noexcept {
90 return m_flag.load(order);
91 }
92
93 private:
94 std::atomic_bool m_flag;
95};
96
97#else
98#error "Missing implementation of shcore::atomic_flag"
99#endif
100
101} // namespace shcore
102
103#endif // ROUTER_SRC_JIT_EXECUTOR_UTILS_ATOMIC_FLAG_H_
static int wait(mysql_cond_t *that, mysql_mutex_t *mutex_arg, const char *, unsigned int)
Definition: mysql_cond_v1_native.cc:62
static mysql_service_status_t clear(reference_caching_channel channel) noexcept
Definition: component.cc:146
Definition: file_system_exceptions.h:34
Definition: gcs_xcom_synode.h:64