MySQL 8.0.40
Source Code Documentation
atomic_bgc_ticket_guard.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_GUARD_H
25#define BINLOG_ATOMIC_BCG_TICKET_GUARD_H
26
27#include <functional>
28#include <limits>
29#include <memory>
30
34
35namespace binlog {
36
37class BgcTicket;
38class AtomicBgcTicket;
39
40class AtomicBgcTicketGuard;
41
42/// @brief RAII opaque for AtomicBgcTicket (set in use/set used synchronization
43/// operations in constructor/destructor)
45 public:
46 virtual ~AtomicBgcTicketGuard();
47
48 // Remove copy-move semantics
51
52 /// @brief "Next" value accessor. Before "release" operation, ticket value is
53 /// set to the returned "next" ticket.
54 /// @returns BgcTicket with next ticket value
55 BgcTicket get_next() const;
56 /// @brief "Previous" value accessor. During the "acquire" operation, ticket
57 /// value is set to the returned "previous" ticket.
58 /// @returns BgcTicket with previous ticket value
59 BgcTicket get_prev() const;
60
61 /// @brief Function used to manually manipulate the "next" ticket value. The
62 /// 'set_next' function will determine the value of the ticket after the
63 /// "release" operation. It can be the same value, but it might be the value
64 /// incremented by one, depending on the current usage.
65 /// @param next Next value for the AtomicBgcTicket referenced by this instance
66 /// of the AtomicBgcTicketGuard
67 void set_next(const BgcTicket &next);
68
69 friend class AtomicBgcTicket;
70
71 protected:
72 /// @brief Constructor
73 /// @param[in] bgcTicket Reference to atomic ticket instance
74 /// @param[in] next_value Before "release" operation, ticket value is set to
75 /// the next_value.
76 AtomicBgcTicketGuard(AtomicBgcTicket &bgcTicket, const BgcTicket &next_value);
77 /// @brief Constructor
78 /// @param[in] bgcTicket Reference to atomic ticket instance
79 /// @param[in] inc_next_before_release Before "release" operation, ticket
80 /// value is set to the value+1 in case inc_next_before_release is equal to
81 /// true
83 bool inc_next_before_release = false);
84
85 protected:
86 std::reference_wrapper<AtomicBgcTicket>
87 m_ref; ///< For threads to synchronize properly, AtomicBgcTicketGuard
88 ///< instances must operate on the same instance of
89 ///< AtomicBgcTicket. This is a reference to atomic Bgc ticket
90 ///< instance, used by different instances of the BgcTicketGuard
91 ///< class (e.g. front/back ticket in BgcTicketManager class)
92 BgcTicket m_next_value; ///< value to be set during the "release" op
93 BgcTicket m_prev_value; ///< previous ticket value, obtained during the
94 ///< "acquire" op
95};
96
97} // namespace binlog
98
99#endif // BINLOG_ATOMIC_BCG_TICKET_GUARD_H
RAII opaque for AtomicBgcTicket (set in use/set used synchronization operations in constructor/destru...
Definition: atomic_bgc_ticket_guard.h:44
BgcTicket m_prev_value
previous ticket value, obtained during the "acquire" op
Definition: atomic_bgc_ticket_guard.h:93
BgcTicket get_next() const
"Next" value accessor.
Definition: atomic_bgc_ticket_guard.cc:46
std::reference_wrapper< AtomicBgcTicket > m_ref
For threads to synchronize properly, AtomicBgcTicketGuard instances must operate on the same instance...
Definition: atomic_bgc_ticket_guard.h:87
BgcTicket get_prev() const
"Previous" value accessor.
Definition: atomic_bgc_ticket_guard.cc:47
AtomicBgcTicketGuard & operator=(AtomicBgcTicketGuard const &)=delete
void set_next(const BgcTicket &next)
Function used to manually manipulate the "next" ticket value.
Definition: atomic_bgc_ticket_guard.cc:48
virtual ~AtomicBgcTicketGuard()
Definition: atomic_bgc_ticket_guard.cc:41
BgcTicket m_next_value
value to be set during the "release" op
Definition: atomic_bgc_ticket_guard.h:92
AtomicBgcTicketGuard(AtomicBgcTicketGuard const &)=delete
Implements atomic ops on BgcTicket object.
Definition: atomic_bgc_ticket.h:43
Represents the Binlog Group Commit Ticket - BGC Ticket.
Definition: bgc_ticket.h:54
Definition: decompressing_event_object_istream.cc:31