MySQL 8.0.39
Source Code Documentation
instrumented_condition_variable.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 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 INSTRUMENTED_CONDITION_VARIABLE_H
25#define INSTRUMENTED_CONDITION_VARIABLE_H
26#include <condition_variable>
27#include <ctime>
28#include <mutex>
31
32namespace mysql {
33
34using std::cv_status;
35using std::unique_lock;
36using std::chrono::time_point;
37
38/**
39 condition_variable is a C++ STL conditional variable
40 (std::condition_variable) implementation using the instrumented MySQL
41 conditional variable component API.
42
43 This allows for P_S instrumentation of conditional variables in components.
44
45 @note Some methods are missing. Implement as needed.
46
47 Example usage:
48 @code
49 #include <mysql/components/library_mysys/instrumented_condition_variable.h>
50 #include <mysql/components/library_mysys/instrumented_mutex.h>
51 namespace x {
52 ...
53 using mysql::condition_varible;
54 ...
55 condition_variable m(KEY_psi_cond);
56 ...
57 m.notifyAll(..);
58 ...
59 };
60 @endcode
61
62 */
64 public:
67 }
70 void notify_one() noexcept { mysql_cond_signal(&m_cond); }
71 void notify_all() noexcept { mysql_cond_broadcast(&m_cond); }
72 void wait(unique_lock<mutex> &lock) {
73 mysql_cond_wait(&m_cond, lock.mutex()->native_handle());
74 }
75 template <class Predicate>
76 void wait(unique_lock<mutex> &lock, Predicate stop_waiting) {
77 while (!stop_waiting()) wait(lock);
78 }
79 template <class Clock, class Duration>
80 cv_status wait_until(unique_lock<mutex> &lock,
81 const time_point<Clock, Duration> &abs_time) {
82 struct timespec tm {
83 Clock::to_time_t(abs_time), 0
84 };
85 return (0 == mysql_cond_timedwait(&m_cond,
86 reinterpret_cast<mysql_mutex_t *>(
87 lock.mutex()->native_handle()),
88 &tm)
89 ? cv_status::no_timeout
91 }
92
93 protected:
96};
97
98} // namespace mysql
99
100#endif // INSTRUMENTED_CONDITION_VARIABLE_H
condition_variable is a C++ STL conditional variable (std::condition_variable) implementation using t...
Definition: instrumented_condition_variable.h:63
~condition_variable()
Definition: instrumented_condition_variable.h:69
PSI_cond_key m_key
Definition: instrumented_condition_variable.h:94
void wait(unique_lock< mutex > &lock, Predicate stop_waiting)
Definition: instrumented_condition_variable.h:76
condition_variable(const condition_variable &)=delete
mysql_cond_t m_cond
Definition: instrumented_condition_variable.h:95
void notify_one() noexcept
Definition: instrumented_condition_variable.h:70
void notify_all() noexcept
Definition: instrumented_condition_variable.h:71
condition_variable(PSI_cond_key key)
Definition: instrumented_condition_variable.h:65
void wait(unique_lock< mutex > &lock)
Definition: instrumented_condition_variable.h:72
cv_status wait_until(unique_lock< mutex > &lock, const time_point< Clock, Duration > &abs_time)
Definition: instrumented_condition_variable.h:80
#define mysql_cond_wait(C, M)
Definition: mysql_cond.h:48
#define mysql_cond_destroy(C)
Definition: mysql_cond.h:45
#define mysql_cond_init(K, C)
Definition: mysql_cond.h:42
#define mysql_cond_timedwait(C, M, T)
Definition: mysql_cond.h:51
#define mysql_cond_signal(C)
Definition: mysql_cond.h:56
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:44
int(* mysql_cond_broadcast)(mysql_cond_t *that, const char *src_file, unsigned int src_line)
Definition: mysql_cond_service.h:52
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
static bool timeout(bool(*wait_condition)())
Timeout function.
Definition: log0meb.cc:496
Definition: instrumented_condition_variable.h:32
required string key
Definition: replication_asynchronous_connection_failover.proto:60
A filter of some sort that is not a join condition (those are stored in JoinPredicate objects).
Definition: access_path.h:117
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50