Coverage Report

Created: 2025-11-16 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/mysql-server/include/mysql/psi/mysql_cond.h
Line
Count
Source
1
/* Copyright (c) 2008, 2025, 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
35
#include "mysql/components/services/bits/mysql_cond_bits.h"
36
#include "mysql/psi/mysql_mutex.h"
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
0
#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
0
#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
130
static inline void inline_mysql_cond_register(const char *category
131
                                              [[maybe_unused]],
132
                                              PSI_cond_info *info
133
                                              [[maybe_unused]],
134
0
                                              int count [[maybe_unused]]) {
135
0
#ifdef HAVE_PSI_COND_INTERFACE
136
0
  PSI_COND_CALL(register_cond)(category, info, count);
137
0
#endif
138
0
}
Unexecuted instantiation: sql_lexer.cc:inline_mysql_cond_register(char const*, PSI_cond_info_v1*, int)
Unexecuted instantiation: my_init.cc:inline_mysql_cond_register(char const*, PSI_cond_info_v1*, int)
Unexecuted instantiation: my_thr_init.cc:inline_mysql_cond_register(char const*, PSI_cond_info_v1*, int)
139
140
static 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
0
                                         int src_line [[maybe_unused]]) {
144
0
#ifdef HAVE_PSI_COND_INTERFACE
145
0
  that->m_psi = PSI_COND_CALL(init_cond)(key, &that->m_cond);
146
0
#else
147
0
  that->m_psi = nullptr;
148
0
#endif
149
0
  return native_cond_init(&that->m_cond);
150
0
}
Unexecuted instantiation: sql_lexer.cc:inline_mysql_cond_init(unsigned int, mysql_cond_t*, char const*, int)
Unexecuted instantiation: my_init.cc:inline_mysql_cond_init(unsigned int, mysql_cond_t*, char const*, int)
Unexecuted instantiation: my_thr_init.cc:inline_mysql_cond_init(unsigned int, mysql_cond_t*, char const*, int)
151
152
static inline int inline_mysql_cond_destroy(mysql_cond_t *that,
153
                                            const char *src_file
154
                                            [[maybe_unused]],
155
0
                                            int src_line [[maybe_unused]]) {
156
0
#ifdef HAVE_PSI_COND_INTERFACE
157
0
  if (that->m_psi != nullptr) {
158
0
    PSI_COND_CALL(destroy_cond)(that->m_psi);
159
0
    that->m_psi = nullptr;
160
0
  }
161
0
#endif
162
0
  return native_cond_destroy(&that->m_cond);
163
0
}
Unexecuted instantiation: sql_lexer.cc:inline_mysql_cond_destroy(mysql_cond_t*, char const*, int)
Unexecuted instantiation: my_init.cc:inline_mysql_cond_destroy(mysql_cond_t*, char const*, int)
Unexecuted instantiation: my_thr_init.cc:inline_mysql_cond_destroy(mysql_cond_t*, char const*, int)
164
165
static inline int inline_mysql_cond_wait(mysql_cond_t *that,
166
                                         mysql_mutex_t *mutex,
167
                                         const char *src_file [[maybe_unused]],
168
0
                                         int src_line [[maybe_unused]]) {
169
0
  int result;
170
0
171
0
#ifdef HAVE_PSI_COND_INTERFACE
172
0
  if (that->m_psi != nullptr) {
173
0
    if (that->m_psi->m_enabled) {
174
0
      /* Instrumentation start */
175
0
      PSI_cond_locker *locker;
176
0
      PSI_cond_locker_state state;
177
0
      locker = PSI_COND_CALL(start_cond_wait)(
178
0
          &state, that->m_psi, mutex->m_psi, PSI_COND_WAIT, src_file, src_line);
179
0
180
0
      /* Instrumented code */
181
0
      result = my_cond_wait(&that->m_cond, &mutex->m_mutex
182
0
#ifdef SAFE_MUTEX
183
0
                            ,
184
0
                            src_file, src_line
185
0
#endif
186
0
      );
187
0
188
0
      /* Instrumentation end */
189
0
      if (locker != nullptr) {
190
0
        PSI_COND_CALL(end_cond_wait)(locker, result);
191
0
      }
192
0
193
0
      return result;
194
0
    }
195
0
  }
196
0
#endif
197
0
198
0
  /* Non instrumented code */
199
0
  result = my_cond_wait(&that->m_cond, &mutex->m_mutex
200
0
#ifdef SAFE_MUTEX
201
0
                        ,
202
0
                        src_file, src_line
203
0
#endif
204
0
  );
205
0
206
0
  return result;
207
0
}
Unexecuted instantiation: sql_lexer.cc:inline_mysql_cond_wait(mysql_cond_t*, mysql_mutex_t*, char const*, int)
Unexecuted instantiation: my_init.cc:inline_mysql_cond_wait(mysql_cond_t*, mysql_mutex_t*, char const*, int)
Unexecuted instantiation: my_thr_init.cc:inline_mysql_cond_wait(mysql_cond_t*, mysql_mutex_t*, char const*, int)
208
209
static inline int inline_mysql_cond_timedwait(
210
    mysql_cond_t *that, mysql_mutex_t *mutex, const struct timespec *abstime,
211
0
    const char *src_file [[maybe_unused]], int src_line [[maybe_unused]]) {
212
0
  int result;
213
0
214
0
#ifdef HAVE_PSI_COND_INTERFACE
215
0
  if (that->m_psi != nullptr) {
216
0
    if (that->m_psi->m_enabled) {
217
0
      /* Instrumentation start */
218
0
      PSI_cond_locker *locker;
219
0
      PSI_cond_locker_state state;
220
0
      locker = PSI_COND_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
221
0
                                              PSI_COND_TIMEDWAIT, src_file,
222
0
                                              src_line);
223
0
224
0
      /* Instrumented code */
225
0
      result = my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime
226
0
#ifdef SAFE_MUTEX
227
0
                                 ,
228
0
                                 src_file, src_line
229
0
#endif
230
0
      );
231
0
232
0
      /* Instrumentation end */
233
0
      if (locker != nullptr) {
234
0
        PSI_COND_CALL(end_cond_wait)(locker, result);
235
0
      }
236
0
237
0
      return result;
238
0
    }
239
0
  }
240
0
#endif
241
0
242
0
  /* Non instrumented code */
243
0
  result = my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime
244
0
#ifdef SAFE_MUTEX
245
0
                             ,
246
0
                             src_file, src_line
247
0
#endif
248
0
  );
249
0
250
0
  return result;
251
0
}
Unexecuted instantiation: sql_lexer.cc:inline_mysql_cond_timedwait(mysql_cond_t*, mysql_mutex_t*, timespec const*, char const*, int)
Unexecuted instantiation: my_init.cc:inline_mysql_cond_timedwait(mysql_cond_t*, mysql_mutex_t*, timespec const*, char const*, int)
Unexecuted instantiation: my_thr_init.cc:inline_mysql_cond_timedwait(mysql_cond_t*, mysql_mutex_t*, timespec const*, char const*, int)
252
253
static inline int inline_mysql_cond_signal(mysql_cond_t *that,
254
                                           const char *src_file
255
                                           [[maybe_unused]],
256
0
                                           int src_line [[maybe_unused]]) {
257
0
  int result;
258
0
#ifdef HAVE_PSI_COND_INTERFACE
259
0
  if (that->m_psi != nullptr) {
260
0
    if (that->m_psi->m_enabled) {
261
0
      PSI_COND_CALL(signal_cond)(that->m_psi);
262
0
    }
263
0
  }
264
0
#endif
265
0
  result = native_cond_signal(&that->m_cond);
266
0
  return result;
267
0
}
Unexecuted instantiation: sql_lexer.cc:inline_mysql_cond_signal(mysql_cond_t*, char const*, int)
Unexecuted instantiation: my_init.cc:inline_mysql_cond_signal(mysql_cond_t*, char const*, int)
Unexecuted instantiation: my_thr_init.cc:inline_mysql_cond_signal(mysql_cond_t*, char const*, int)
268
269
static inline int inline_mysql_cond_broadcast(mysql_cond_t *that,
270
                                              const char *src_file
271
                                              [[maybe_unused]],
272
0
                                              int src_line [[maybe_unused]]) {
273
0
  int result;
274
0
#ifdef HAVE_PSI_COND_INTERFACE
275
0
  if (that->m_psi != nullptr) {
276
0
    if (that->m_psi->m_enabled) {
277
0
      PSI_COND_CALL(broadcast_cond)(that->m_psi);
278
0
    }
279
0
  }
280
0
#endif
281
0
  result = native_cond_broadcast(&that->m_cond);
282
0
  return result;
283
0
}
Unexecuted instantiation: sql_lexer.cc:inline_mysql_cond_broadcast(mysql_cond_t*, char const*, int)
Unexecuted instantiation: my_init.cc:inline_mysql_cond_broadcast(mysql_cond_t*, char const*, int)
Unexecuted instantiation: my_thr_init.cc:inline_mysql_cond_broadcast(mysql_cond_t*, char const*, int)
284
285
#endif /* DISABLE_MYSQL_THREAD_H */
286
287
/** @} (end of group psi_api_cond) */
288
289
#endif