MySQL 9.1.0
Source Code Documentation
atomic_bgc_ticket.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef BINLOG_ATOMIC_BCG_TICKET_H
25#define BINLOG_ATOMIC_BCG_TICKET_H
26
27#include <functional>
28#include <limits>
29#include <memory>
30
34
35namespace binlog {
36
37class AtomicBgcTicketGuard;
38class BgcTicket;
39
40/// @brief Implements atomic ops on BgcTicket object
41/// @details Impl based on Aligned_atomic
42/// @see Bgc_ticket_manager
44 public:
45 virtual ~AtomicBgcTicket() = default;
46
47 // Remove copy-move semantics
52
53 /// @brief Copying ctor
54 /// @param[in] src Pattern to copy from
55 /// @details AtomicBgcTicket is created based on src BgcTicket object
56 AtomicBgcTicket(const BgcTicket &src);
57
58 /// @brief Copying ctor
59 /// @param[in] src Pattern to copy from
60 /// @details AtomicBgcTicket is created based on src ValueType object
61 explicit AtomicBgcTicket(const BgcTicket::ValueType &src);
62
64 friend class BgcTicket;
65
66 /// @brief Creates the "lock" that is held for the returned
67 /// AtomicBgcTicketGuard object lifetime
68 /// @param[in] inc_next_before_release Before "release" operation, ticket
69 /// value is set to the value+1 in case inc_next_before_acquire is equal false
70 /// and inc_next_before_release is equal to true
71 AtomicBgcTicketGuard scoped_lock(bool inc_next_before_release = false);
72 /// @brief Creates the "lock" that is held for the returned
73 /// AtomicBgcTicketGuard object lifetime
75
76 /// @brief Stream operator impl for AtomicBgcTicket class
77 /// @param[in] os Reference to stream obj
78 /// @param[in] arg Constant reference to AtomicBgcTicket object
79 /// @returns Reference to changed stream obj
80 friend std::ostream &operator<<(std::ostream &os, const AtomicBgcTicket &arg);
81
82 /// @brief Ticket mutator, atomic store op
83 /// @param[in] value Sets atomically m_ticket internal variable to "value"
84 void store(const BgcTicket &value);
85
86 /// @brief Ticket accessor, atomic load op
87 /// @returns BGC Ticket obtained during the atomic load op
88 BgcTicket load() const;
89
90 protected:
91 /// @brief Sets ticket synchronization value to "in use". Only one thread is
92 /// allowed to get into the critical section that starts with the "set_in_use"
93 /// op and ends with the "set_used"
94 /// @param[in] inc_next_before_acquire During the "acquire" operation, ticket
95 /// value is set to the value+1 in case inc_next_before_acquire is equal to
96 /// true.
97 /// @param[in] inc_next_before_release Before "release" operation, ticket
98 /// value is set to the value+1 in case inc_next_before_acquire is equal
99 /// false.
100 /// @returns previous ticket value (obtained before acquire op) and next
101 /// ticket value (set before release op)
102 std::pair<BgcTicket, BgcTicket> set_in_use(
103 bool inc_next_before_acquire = false,
104 bool inc_next_before_release = false);
105
106 /// @brief Sets ticket synchronization value to "used/free". Only one thread
107 /// is allowed to get into the critical section that starts with the
108 /// "set_in_use" op and ends with the "set_used"
109 /// @param[in] next_value Next ticket value set during the "release" op.
110 void set_used(const BgcTicket &next_value);
112 m_ticket; ///< internal ticket representation
113};
114
115} // namespace binlog
116
117#endif // BINLOG_ATOMIC_BCG_TICKET_H
RAII opaque for AtomicBgcTicket (set in use/set used synchronization operations in constructor/destru...
Definition: atomic_bgc_ticket_guard.h:44
Implements atomic ops on BgcTicket object.
Definition: atomic_bgc_ticket.h:43
AtomicBgcTicket(AtomicBgcTicket &&)=delete
AtomicBgcTicket & operator=(AtomicBgcTicket const &)=delete
void set_used(const BgcTicket &next_value)
Sets ticket synchronization value to "used/free".
Definition: atomic_bgc_ticket.cc:78
BgcTicket load() const
Ticket accessor, atomic load op.
Definition: atomic_bgc_ticket.cc:63
AtomicBgcTicket(AtomicBgcTicket const &)=delete
virtual ~AtomicBgcTicket()=default
memory::Aligned_atomic< BgcTicket::ValueType > m_ticket
internal ticket representation
Definition: atomic_bgc_ticket.h:112
AtomicBgcTicketGuard scoped_lock(bool inc_next_before_release=false)
Creates the "lock" that is held for the returned AtomicBgcTicketGuard object lifetime.
Definition: atomic_bgc_ticket.cc:69
void store(const BgcTicket &value)
Ticket mutator, atomic store op.
Definition: atomic_bgc_ticket.cc:65
std::pair< BgcTicket, BgcTicket > set_in_use(bool inc_next_before_acquire=false, bool inc_next_before_release=false)
Sets ticket synchronization value to "in use".
Definition: atomic_bgc_ticket.cc:34
friend std::ostream & operator<<(std::ostream &os, const AtomicBgcTicket &arg)
Stream operator impl for AtomicBgcTicket class.
Definition: atomic_bgc_ticket.cc:58
AtomicBgcTicket & operator=(AtomicBgcTicket &&)=delete
Represents the Binlog Group Commit Ticket - BGC Ticket.
Definition: bgc_ticket.h:54
std::uint64_t ValueType
Definition: bgc_ticket.h:56
Templated class that encapsulates an std::atomic within a byte buffer that is padded to the processor...
Definition: aligned_atomic.h:158
Definition: pfs.cc:38