MySQL 9.0.0
Source Code Documentation
mysql_cond.h
Go to the documentation of this file.
1/* Copyright (c) 2008, 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 MYSQL_COND_H
25#define MYSQL_COND_H
26
27/**
28 @file include/mysql/psi/mysql_cond.h
29 Instrumentation helpers for conditions.
30*/
31
32/* HAVE_PSI_*_INTERFACE */
33#include "my_psi_config.h" // IWYU pragma: keep
34
37#include "mysql/psi/psi_cond.h"
38#include "thr_cond.h"
39
40#if defined(MYSQL_SERVER) || defined(PFS_DIRECT_CALL)
41/* PSI_COND_CALL() as direct call. */
42#include "pfs_cond_provider.h" // IWYU pragma: keep
43#endif
44
45#ifndef PSI_COND_CALL
46#define PSI_COND_CALL(M) psi_cond_service->M
47#endif
48
49/**
50 @defgroup psi_api_cond Cond Instrumentation (API)
51 @ingroup psi_api
52 @{
53*/
54
55#ifndef DISABLE_MYSQL_THREAD_H
56
57/**
58 @def mysql_cond_register(P1, P2, P3)
59 Cond registration.
60*/
61#define mysql_cond_register(P1, P2, P3) inline_mysql_cond_register(P1, P2, P3)
62
63/**
64 @def mysql_cond_init(K, C)
65 Instrumented cond_init.
66 @c mysql_cond_init is a replacement for @c pthread_cond_init.
67 Note that pthread_condattr_t is not supported in MySQL.
68 @param C The cond to initialize
69 @param K The PSI_cond_key for this instrumented cond
70
71*/
72
73#define mysql_cond_init(K, C) mysql_cond_init_with_src(K, C, __FILE__, __LINE__)
74
75#define mysql_cond_init_with_src(K, C, F, L) inline_mysql_cond_init(K, C, F, L)
76
77/**
78 @def mysql_cond_destroy(C)
79 Instrumented cond_destroy.
80 @c mysql_cond_destroy is a drop-in replacement for @c pthread_cond_destroy.
81*/
82#define mysql_cond_destroy(C) mysql_cond_destroy_with_src(C, __FILE__, __LINE__)
83
84#define mysql_cond_destroy_with_src(C, F, L) inline_mysql_cond_destroy(C, F, L)
85
86/**
87 @def mysql_cond_wait(C)
88 Instrumented cond_wait.
89 @c mysql_cond_wait is a drop-in replacement for @c native_cond_wait.
90*/
91#define mysql_cond_wait(C, M) mysql_cond_wait_with_src(C, M, __FILE__, __LINE__)
92
93#define mysql_cond_wait_with_src(C, M, F, L) inline_mysql_cond_wait(C, M, F, L)
94
95/**
96 @def mysql_cond_timedwait(C, M, W)
97 Instrumented cond_timedwait.
98 @c mysql_cond_timedwait is a drop-in replacement
99 for @c native_cond_timedwait.
100*/
101
102#define mysql_cond_timedwait(C, M, W) \
103 mysql_cond_timedwait_with_src(C, M, W, __FILE__, __LINE__)
104
105#define mysql_cond_timedwait_with_src(C, M, W, F, L) \
106 inline_mysql_cond_timedwait(C, M, W, F, L)
107
108/**
109 @def mysql_cond_signal(C)
110 Instrumented cond_signal.
111 @c mysql_cond_signal is a drop-in replacement for @c pthread_cond_signal.
112*/
113
114#define mysql_cond_signal(C) mysql_cond_signal_with_src(C, __FILE__, __LINE__)
115
116#define mysql_cond_signal_with_src(C, F, L) inline_mysql_cond_signal(C, F, L)
117
118/**
119 @def mysql_cond_broadcast(C)
120 Instrumented cond_broadcast.
121 @c mysql_cond_broadcast is a drop-in replacement
122 for @c pthread_cond_broadcast.
123*/
124#define mysql_cond_broadcast(C) \
125 mysql_cond_broadcast_with_src(C, __FILE__, __LINE__)
126
127#define mysql_cond_broadcast_with_src(C, F, L) \
128 inline_mysql_cond_broadcast(C, F, L)
129
130static inline void inline_mysql_cond_register(const char *category
131 [[maybe_unused]],
132 PSI_cond_info *info
133 [[maybe_unused]],
134 int count [[maybe_unused]]) {
135#ifdef HAVE_PSI_COND_INTERFACE
136 PSI_COND_CALL(register_cond)(category, info, count);
137#endif
138}
139
140static inline int inline_mysql_cond_init(PSI_cond_key key [[maybe_unused]],
141 mysql_cond_t *that,
142 const char *src_file [[maybe_unused]],
143 int src_line [[maybe_unused]]) {
144#ifdef HAVE_PSI_COND_INTERFACE
145 that->m_psi = PSI_COND_CALL(init_cond)(key, &that->m_cond);
146#else
147 that->m_psi = nullptr;
148#endif
149 return native_cond_init(&that->m_cond);
150}
151
153 const char *src_file
154 [[maybe_unused]],
155 int src_line [[maybe_unused]]) {
156#ifdef HAVE_PSI_COND_INTERFACE
157 if (that->m_psi != nullptr) {
159 that->m_psi = nullptr;
160 }
161#endif
162 return native_cond_destroy(&that->m_cond);
163}
164
165static inline int inline_mysql_cond_wait(mysql_cond_t *that,
166 mysql_mutex_t *mutex,
167 const char *src_file [[maybe_unused]],
168 int src_line [[maybe_unused]]) {
169 int result;
170
171#ifdef HAVE_PSI_COND_INTERFACE
172 if (that->m_psi != nullptr) {
173 if (that->m_psi->m_enabled) {
174 /* Instrumentation start */
175 PSI_cond_locker *locker;
177 locker = PSI_COND_CALL(start_cond_wait)(
178 &state, that->m_psi, mutex->m_psi, PSI_COND_WAIT, src_file, src_line);
179
180 /* Instrumented code */
181 result = my_cond_wait(&that->m_cond, &mutex->m_mutex
182#ifdef SAFE_MUTEX
183 ,
184 src_file, src_line
185#endif
186 );
187
188 /* Instrumentation end */
189 if (locker != nullptr) {
190 PSI_COND_CALL(end_cond_wait)(locker, result);
191 }
192
193 return result;
194 }
195 }
196#endif
197
198 /* Non instrumented code */
199 result = my_cond_wait(&that->m_cond, &mutex->m_mutex
200#ifdef SAFE_MUTEX
201 ,
202 src_file, src_line
203#endif
204 );
205
206 return result;
207}
208
210 mysql_cond_t *that, mysql_mutex_t *mutex, const struct timespec *abstime,
211 const char *src_file [[maybe_unused]], int src_line [[maybe_unused]]) {
212 int result;
213
214#ifdef HAVE_PSI_COND_INTERFACE
215 if (that->m_psi != nullptr) {
216 if (that->m_psi->m_enabled) {
217 /* Instrumentation start */
218 PSI_cond_locker *locker;
220 locker = PSI_COND_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
221 PSI_COND_TIMEDWAIT, src_file,
222 src_line);
223
224 /* Instrumented code */
225 result = my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime
226#ifdef SAFE_MUTEX
227 ,
228 src_file, src_line
229#endif
230 );
231
232 /* Instrumentation end */
233 if (locker != nullptr) {
234 PSI_COND_CALL(end_cond_wait)(locker, result);
235 }
236
237 return result;
238 }
239 }
240#endif
241
242 /* Non instrumented code */
243 result = my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime
244#ifdef SAFE_MUTEX
245 ,
246 src_file, src_line
247#endif
248 );
249
250 return result;
251}
252
254 const char *src_file
255 [[maybe_unused]],
256 int src_line [[maybe_unused]]) {
257 int result;
258#ifdef HAVE_PSI_COND_INTERFACE
259 if (that->m_psi != nullptr) {
260 if (that->m_psi->m_enabled) {
261 PSI_COND_CALL(signal_cond)(that->m_psi);
262 }
263 }
264#endif
266 return result;
267}
268
270 const char *src_file
271 [[maybe_unused]],
272 int src_line [[maybe_unused]]) {
273 int result;
274#ifdef HAVE_PSI_COND_INTERFACE
275 if (that->m_psi != nullptr) {
276 if (that->m_psi->m_enabled) {
277 PSI_COND_CALL(broadcast_cond)(that->m_psi);
278 }
279 }
280#endif
282 return result;
283}
284
285#endif /* DISABLE_MYSQL_THREAD_H */
286
287/** @} (end of group psi_api_cond) */
288
289#endif
#define PSI_COND_CALL(M)
Definition: psi_cond.h:36
void destroy_cond(PFS_cond *pfs)
Destroy instrumentation for a condition instance.
Definition: pfs_instr.cc:473
struct PSI_cond_locker PSI_cond_locker
Definition: psi_cond_bits.h:72
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:44
@ PSI_COND_WAIT
Wait.
Definition: psi_cond_bits.h:77
@ PSI_COND_TIMEDWAIT
Wait, with timeout.
Definition: psi_cond_bits.h:79
static int inline_mysql_cond_init(PSI_cond_key key, mysql_cond_t *that, const char *src_file, int src_line)
Definition: mysql_cond.h:140
static void inline_mysql_cond_register(const char *category, PSI_cond_info *info, int count)
Definition: mysql_cond.h:130
static int inline_mysql_cond_timedwait(mysql_cond_t *that, mysql_mutex_t *mutex, const struct timespec *abstime, const char *src_file, int src_line)
Definition: mysql_cond.h:209
static int inline_mysql_cond_broadcast(mysql_cond_t *that, const char *src_file, int src_line)
Definition: mysql_cond.h:269
static int inline_mysql_cond_destroy(mysql_cond_t *that, const char *src_file, int src_line)
Definition: mysql_cond.h:152
static int inline_mysql_cond_wait(mysql_cond_t *that, mysql_mutex_t *mutex, const char *src_file, int src_line)
Definition: mysql_cond.h:165
static int inline_mysql_cond_signal(mysql_cond_t *that, const char *src_file, int src_line)
Definition: mysql_cond.h:253
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
static int count
Definition: myisam_ftdump.cc:45
Instrumentation helpers for conditions.
static const char * category
Definition: sha2_password.cc:170
Performance schema instrumentation (declarations).
struct result result
Definition: result.h:34
Instrumentation helpers for mutexes.
Performance schema instrumentation interface.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Condition information.
Definition: psi_cond_bits.h:88
State data storage for start_cond_wait_v1_t.
Definition: psi_cond_bits.h:118
bool m_enabled
Instrumentation is enabled.
Definition: psi_bits.h:191
An instrumented cond structure.
Definition: mysql_cond_bits.h:50
struct PSI_cond * m_psi
The instrumentation hook.
Definition: mysql_cond_bits.h:58
native_cond_t m_cond
The real condition.
Definition: mysql_cond_bits.h:52
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
struct PSI_mutex * m_psi
The instrumentation hook.
Definition: mysql_mutex_bits.h:58
my_mutex_t m_mutex
The real mutex.
Definition: mysql_mutex_bits.h:52
Definition: result.h:30
MySQL condition variable implementation.
static int native_cond_init(native_cond_t *cond)
Definition: thr_cond.h:74
static int native_cond_broadcast(native_cond_t *cond)
Definition: thr_cond.h:122
static int my_cond_timedwait(native_cond_t *cond, my_mutex_t *mp, const struct timespec *abstime)
Definition: thr_cond.h:139
static int my_cond_wait(native_cond_t *cond, my_mutex_t *mp)
Definition: thr_cond.h:153
static int native_cond_destroy(native_cond_t *cond)
Definition: thr_cond.h:84
static int native_cond_signal(native_cond_t *cond)
Definition: thr_cond.h:113