1 /* Copyright (c) 2011, 2021, 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 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 Foundation,
21   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef MYSQL_IDLE_H
24 #define MYSQL_IDLE_H
25 
26 /**
27   @file mysql/psi/mysql_idle.h
28   Instrumentation helpers for idle waits.
29 */
30 
31 #include "mysql/psi/psi.h"
32 
33 #ifndef PSI_IDLE_CALL
34 #define PSI_IDLE_CALL(M) PSI_DYNAMIC_CALL(M)
35 #endif
36 
37 /**
38   @defgroup Idle_instrumentation Idle Instrumentation
39   @ingroup Instrumentation_interface
40   @{
41 */
42 
43 /**
44   @def MYSQL_START_IDLE_WAIT
45   Instrumentation helper for table io_waits.
46   This instrumentation marks the start of a wait event.
47   @param LOCKER the locker
48   @param STATE the locker state
49   @sa MYSQL_END_IDLE_WAIT.
50 */
51 #ifdef HAVE_PSI_IDLE_INTERFACE
52   #define MYSQL_START_IDLE_WAIT(LOCKER, STATE) \
53     LOCKER= inline_mysql_start_idle_wait(STATE, __FILE__, __LINE__)
54 #else
55   #define MYSQL_START_IDLE_WAIT(LOCKER, STATE) \
56     do {} while (0)
57 #endif
58 
59 /**
60   @def MYSQL_END_IDLE_WAIT
61   Instrumentation helper for idle waits.
62   This instrumentation marks the end of a wait event.
63   @param LOCKER the locker
64   @sa MYSQL_START_IDLE_WAIT.
65 */
66 #ifdef HAVE_PSI_IDLE_INTERFACE
67   #define MYSQL_END_IDLE_WAIT(LOCKER) \
68     inline_mysql_end_idle_wait(LOCKER)
69 #else
70   #define MYSQL_END_IDLE_WAIT(LOCKER) \
71     do {} while (0)
72 #endif
73 
74 #ifdef HAVE_PSI_IDLE_INTERFACE
75 /**
76   Instrumentation calls for MYSQL_START_IDLE_WAIT.
77   @sa MYSQL_END_IDLE_WAIT.
78 */
79 static inline struct PSI_idle_locker *
inline_mysql_start_idle_wait(PSI_idle_locker_state * state,const char * src_file,int src_line)80 inline_mysql_start_idle_wait(PSI_idle_locker_state *state,
81                              const char *src_file, int src_line)
82 {
83   struct PSI_idle_locker *locker;
84   locker= PSI_IDLE_CALL(start_idle_wait)(state, src_file, src_line);
85   return locker;
86 }
87 
88 /**
89   Instrumentation calls for MYSQL_END_IDLE_WAIT.
90   @sa MYSQL_START_IDLE_WAIT.
91 */
92 static inline void
inline_mysql_end_idle_wait(struct PSI_idle_locker * locker)93 inline_mysql_end_idle_wait(struct PSI_idle_locker *locker)
94 {
95   if (likely(locker != NULL))
96     PSI_IDLE_CALL(end_idle_wait)(locker);
97 }
98 #endif
99 
100 /** @} (end of group Idle_instrumentation) */
101 
102 #endif
103 
104