MySQL  8.0.17
Source Code Documentation
mysql_cond.h
Go to the documentation of this file.
1 /* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
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 also distributed 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 included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef MYSQL_COND_H
24 #define MYSQL_COND_H
25 
26 /**
27  @file include/mysql/psi/mysql_cond.h
28  Instrumentation helpers for conditions.
29 */
30 
32 #include "mysql/psi/mysql_mutex.h"
33 #include "mysql/psi/psi_cond.h"
34 #include "thr_cond.h"
35 #ifdef MYSQL_SERVER
36 #ifndef MYSQL_DYNAMIC_PLUGIN
37 #include "pfs_cond_provider.h"
38 #endif
39 #endif
40 
41 #ifndef PSI_COND_CALL
42 #define PSI_COND_CALL(M) psi_cond_service->M
43 #endif
44 
45 /**
46  @defgroup psi_api_cond Cond Instrumentation (API)
47  @ingroup psi_api
48  @{
49 */
50 
51 #ifndef DISABLE_MYSQL_THREAD_H
52 
53 /**
54  @def mysql_cond_register(P1, P2, P3)
55  Cond registration.
56 */
57 #define mysql_cond_register(P1, P2, P3) inline_mysql_cond_register(P1, P2, P3)
58 
59 /**
60  @def mysql_cond_init(K, C)
61  Instrumented cond_init.
62  @c mysql_cond_init is a replacement for @c pthread_cond_init.
63  Note that pthread_condattr_t is not supported in MySQL.
64  @param C The cond to initialize
65  @param K The PSI_cond_key for this instrumented cond
66 
67 */
68 
69 #define mysql_cond_init(K, C) mysql_cond_init_with_src(K, C, __FILE__, __LINE__)
70 
71 #define mysql_cond_init_with_src(K, C, F, L) inline_mysql_cond_init(K, C, F, L)
72 
73 /**
74  @def mysql_cond_destroy(C)
75  Instrumented cond_destroy.
76  @c mysql_cond_destroy is a drop-in replacement for @c pthread_cond_destroy.
77 */
78 #define mysql_cond_destroy(C) mysql_cond_destroy_with_src(C, __FILE__, __LINE__)
79 
80 #define mysql_cond_destroy_with_src(C, F, L) inline_mysql_cond_destroy(C, F, L)
81 
82 /**
83  @def mysql_cond_wait(C)
84  Instrumented cond_wait.
85  @c mysql_cond_wait is a drop-in replacement for @c native_cond_wait.
86 */
87 #define mysql_cond_wait(C, M) mysql_cond_wait_with_src(C, M, __FILE__, __LINE__)
88 
89 #define mysql_cond_wait_with_src(C, M, F, L) inline_mysql_cond_wait(C, M, F, L)
90 
91 /**
92  @def mysql_cond_timedwait(C, M, W)
93  Instrumented cond_timedwait.
94  @c mysql_cond_timedwait is a drop-in replacement
95  for @c native_cond_timedwait.
96 */
97 
98 #define mysql_cond_timedwait(C, M, W) \
99  mysql_cond_timedwait_with_src(C, M, W, __FILE__, __LINE__)
100 
101 #define mysql_cond_timedwait_with_src(C, M, W, F, L) \
102  inline_mysql_cond_timedwait(C, M, W, F, L)
103 
104 /**
105  @def mysql_cond_signal(C)
106  Instrumented cond_signal.
107  @c mysql_cond_signal is a drop-in replacement for @c pthread_cond_signal.
108 */
109 
110 #define mysql_cond_signal(C) mysql_cond_signal_with_src(C, __FILE__, __LINE__)
111 
112 #define mysql_cond_signal_with_src(C, F, L) inline_mysql_cond_signal(C, F, L)
113 
114 /**
115  @def mysql_cond_broadcast(C)
116  Instrumented cond_broadcast.
117  @c mysql_cond_broadcast is a drop-in replacement
118  for @c pthread_cond_broadcast.
119 */
120 #define mysql_cond_broadcast(C) \
121  mysql_cond_broadcast_with_src(C, __FILE__, __LINE__)
122 
123 #define mysql_cond_broadcast_with_src(C, F, L) \
124  inline_mysql_cond_broadcast(C, F, L)
125 
126 static inline void inline_mysql_cond_register(
127  const char *category MY_ATTRIBUTE((unused)),
128  PSI_cond_info *info MY_ATTRIBUTE((unused)),
129  int count MY_ATTRIBUTE((unused))) {
130 #ifdef HAVE_PSI_COND_INTERFACE
131  PSI_COND_CALL(register_cond)(category, info, count);
132 #endif
133 }
134 
135 static inline int inline_mysql_cond_init(
136  PSI_cond_key key MY_ATTRIBUTE((unused)), mysql_cond_t *that,
137  const char *src_file MY_ATTRIBUTE((unused)),
138  int src_line MY_ATTRIBUTE((unused))) {
139 #ifdef HAVE_PSI_COND_INTERFACE
140  that->m_psi = PSI_COND_CALL(init_cond)(key, &that->m_cond);
141 #else
142  that->m_psi = NULL;
143 #endif
144  return native_cond_init(&that->m_cond);
145 }
146 
147 static inline int inline_mysql_cond_destroy(
148  mysql_cond_t *that, const char *src_file MY_ATTRIBUTE((unused)),
149  int src_line MY_ATTRIBUTE((unused))) {
150 #ifdef HAVE_PSI_COND_INTERFACE
151  if (that->m_psi != NULL) {
153  that->m_psi = NULL;
154  }
155 #endif
156  return native_cond_destroy(&that->m_cond);
157 }
158 
159 static inline int inline_mysql_cond_wait(
161  const char *src_file MY_ATTRIBUTE((unused)),
162  int src_line MY_ATTRIBUTE((unused))) {
163  int result;
164 
165 #ifdef HAVE_PSI_COND_INTERFACE
166  if (that->m_psi != NULL) {
167  /* Instrumentation start */
168  PSI_cond_locker *locker;
169  PSI_cond_locker_state state;
170  locker = PSI_COND_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
171  PSI_COND_WAIT, src_file, src_line);
172 
173  /* Instrumented code */
174  result = my_cond_wait(&that->m_cond, &mutex->m_mutex
175 #ifdef SAFE_MUTEX
176  ,
177  src_file, src_line
178 #endif
179  );
180 
181  /* Instrumentation end */
182  if (locker != NULL) {
183  PSI_COND_CALL(end_cond_wait)(locker, result);
184  }
185 
186  return result;
187  }
188 #endif
189 
190  /* Non instrumented code */
191  result = my_cond_wait(&that->m_cond, &mutex->m_mutex
192 #ifdef SAFE_MUTEX
193  ,
194  src_file, src_line
195 #endif
196  );
197 
198  return result;
199 }
200 
201 static inline int inline_mysql_cond_timedwait(
202  mysql_cond_t *that, mysql_mutex_t *mutex, const struct timespec *abstime,
203  const char *src_file MY_ATTRIBUTE((unused)),
204  int src_line MY_ATTRIBUTE((unused))) {
205  int result;
206 
207 #ifdef HAVE_PSI_COND_INTERFACE
208  if (that->m_psi != NULL) {
209  /* Instrumentation start */
210  PSI_cond_locker *locker;
211  PSI_cond_locker_state state;
212  locker =
213  PSI_COND_CALL(start_cond_wait)(&state, that->m_psi, mutex->m_psi,
214  PSI_COND_TIMEDWAIT, src_file, src_line);
215 
216  /* Instrumented code */
217  result = my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime
218 #ifdef SAFE_MUTEX
219  ,
220  src_file, src_line
221 #endif
222  );
223 
224  /* Instrumentation end */
225  if (locker != NULL) {
226  PSI_COND_CALL(end_cond_wait)(locker, result);
227  }
228 
229  return result;
230  }
231 #endif
232 
233  /* Non instrumented code */
234  result = my_cond_timedwait(&that->m_cond, &mutex->m_mutex, abstime
235 #ifdef SAFE_MUTEX
236  ,
237  src_file, src_line
238 #endif
239  );
240 
241  return result;
242 }
243 
244 static inline int inline_mysql_cond_signal(
245  mysql_cond_t *that, const char *src_file MY_ATTRIBUTE((unused)),
246  int src_line MY_ATTRIBUTE((unused))) {
247  int result;
248 #ifdef HAVE_PSI_COND_INTERFACE
249  if (that->m_psi != NULL) {
250  PSI_COND_CALL(signal_cond)(that->m_psi);
251  }
252 #endif
253  result = native_cond_signal(&that->m_cond);
254  return result;
255 }
256 
257 static inline int inline_mysql_cond_broadcast(
258  mysql_cond_t *that, const char *src_file MY_ATTRIBUTE((unused)),
259  int src_line MY_ATTRIBUTE((unused))) {
260  int result;
261 #ifdef HAVE_PSI_COND_INTERFACE
262  if (that->m_psi != NULL) {
263  PSI_COND_CALL(broadcast_cond)(that->m_psi);
264  }
265 #endif
266  result = native_cond_broadcast(&that->m_cond);
267  return result;
268 }
269 
270 #endif /* DISABLE_MYSQL_THREAD_H */
271 
272 /** @} (end of group psi_api_cond) */
273 
274 #endif
Instrumentation helpers for mutexes.
Wait.
Definition: psi_cond_bits.h:74
Performance schema instrumentation interface.
static int native_cond_init(native_cond_t *cond)
Definition: thr_cond.h:73
ssize_t count
Definition: memcached.c:386
void destroy_cond(PFS_cond *pfs)
Destroy instrumentation for a condition instance.
Definition: pfs_instr.cc:428
An instrumented cond structure.
Definition: mysql_cond_bits.h:49
static int my_cond_wait(native_cond_t *cond, my_mutex_t *mp)
Definition: thr_cond.h:153
pthread_mutex_t mutex
Definition: memcached.c:384
static int native_cond_destroy(native_cond_t *cond)
Definition: thr_cond.h:83
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
struct PSI_cond_locker PSI_cond_locker
Definition: psi_cond_bits.h:69
static void inline_mysql_cond_register(const char *category, PSI_cond_info *info, int count)
Definition: mysql_cond.h:126
Instrumentation helpers for conditions.
static pthread_cond_t init_cond
Definition: thread.c:74
Condition information.
Definition: psi_cond_bits.h:85
State data storage for start_cond_wait_v1_t.
Definition: psi_cond_bits.h:115
struct PSI_cond * m_psi
The instrumentation hook.
Definition: mysql_cond_bits.h:57
unsigned int PSI_cond_key
Instrumented cond key.
Definition: psi_cond_bits.h:41
static int native_cond_broadcast(native_cond_t *cond)
Definition: thr_cond.h:122
static int inline_mysql_cond_signal(mysql_cond_t *that, const char *src_file, int src_line)
Definition: mysql_cond.h:244
static int inline_mysql_cond_destroy(mysql_cond_t *that, const char *src_file, int src_line)
Definition: mysql_cond.h:147
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:201
static int my_cond_timedwait(native_cond_t *cond, my_mutex_t *mp, const struct timespec *abstime)
Definition: thr_cond.h:139
static int inline_mysql_cond_broadcast(mysql_cond_t *that, const char *src_file, int src_line)
Definition: mysql_cond.h:257
#define PSI_COND_CALL(M)
Definition: psi_cond.h:31
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:135
Performance schema instrumentation (declarations).
static const char * key
Definition: suite_stubs.c:14
static const char * category
Definition: sha2_password.cc:168
native_cond_t m_cond
The real condition.
Definition: mysql_cond_bits.h:51
Wait, with timeout.
Definition: psi_cond_bits.h:76
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
Log info(cout, "NOTE")
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:159
static time_t abstime(const rel_time_t exptime)
Convert the relative time to an absolute time (relative to EPOC ;) )
Definition: memcached.c:271
static int native_cond_signal(native_cond_t *cond)
Definition: thr_cond.h:113
MySQL condition variable implementation.