1 /* Copyright (c) 2010, 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_TABLE_H
24 #define MYSQL_TABLE_H
25 
26 /**
27   @file mysql/psi/mysql_table.h
28   Instrumentation helpers for table io.
29 */
30 
31 #include "mysql/psi/psi.h"
32 
33 #ifndef PSI_TABLE_CALL
34 #define PSI_TABLE_CALL(M) PSI_DYNAMIC_CALL(M)
35 #endif
36 
37 /**
38   @defgroup Table_instrumentation Table Instrumentation
39   @ingroup Instrumentation_interface
40   @{
41 */
42 
43 /**
44   @def MYSQL_TABLE_WAIT_VARIABLES
45   Instrumentation helper for table waits.
46   This instrumentation declares local variables.
47   Do not use a ';' after this macro
48   @param LOCKER the locker
49   @param STATE the locker state
50   @sa MYSQL_START_TABLE_IO_WAIT.
51   @sa MYSQL_END_TABLE_IO_WAIT.
52   @sa MYSQL_START_TABLE_LOCK_WAIT.
53   @sa MYSQL_END_TABLE_LOCK_WAIT.
54 */
55 #ifdef HAVE_PSI_TABLE_INTERFACE
56   #define MYSQL_TABLE_WAIT_VARIABLES(LOCKER, STATE) \
57     struct PSI_table_locker* LOCKER; \
58     PSI_table_locker_state STATE;
59 #else
60   #define MYSQL_TABLE_WAIT_VARIABLES(LOCKER, STATE)
61 #endif
62 
63 /**
64   @def MYSQL_START_TABLE_LOCK_WAIT
65   Instrumentation helper for table lock waits.
66   This instrumentation marks the start of a wait event.
67   @param LOCKER the locker
68   @param STATE the locker state
69   @param PSI the instrumented table
70   @param OP the table operation to be performed
71   @param FLAGS per table operation flags.
72   @sa MYSQL_END_TABLE_LOCK_WAIT.
73 */
74 #ifdef HAVE_PSI_TABLE_INTERFACE
75   #define MYSQL_START_TABLE_LOCK_WAIT(LOCKER, STATE, PSI, OP, FLAGS) \
76     LOCKER= inline_mysql_start_table_lock_wait(STATE, PSI, \
77                                                OP, FLAGS, __FILE__, __LINE__)
78 #else
79   #define MYSQL_START_TABLE_LOCK_WAIT(LOCKER, STATE, PSI, OP, FLAGS) \
80     do {} while (0)
81 #endif
82 
83 /**
84   @def MYSQL_END_TABLE_LOCK_WAIT
85   Instrumentation helper for table lock waits.
86   This instrumentation marks the end of a wait event.
87   @param LOCKER the locker
88   @sa MYSQL_START_TABLE_LOCK_WAIT.
89 */
90 #ifdef HAVE_PSI_TABLE_INTERFACE
91   #define MYSQL_END_TABLE_LOCK_WAIT(LOCKER) \
92     inline_mysql_end_table_lock_wait(LOCKER)
93 #else
94   #define MYSQL_END_TABLE_LOCK_WAIT(LOCKER) \
95     do {} while (0)
96 #endif
97 
98 #ifdef HAVE_PSI_TABLE_INTERFACE
99   #define MYSQL_UNLOCK_TABLE(T) \
100     inline_mysql_unlock_table(T)
101 #else
102   #define MYSQL_UNLOCK_TABLE(T) \
103     do {} while (0)
104 #endif
105 
106 #ifdef HAVE_PSI_TABLE_INTERFACE
107 /**
108   Instrumentation calls for MYSQL_START_TABLE_LOCK_WAIT.
109   @sa MYSQL_END_TABLE_LOCK_WAIT.
110 */
111 static inline struct PSI_table_locker *
inline_mysql_start_table_lock_wait(PSI_table_locker_state * state,struct PSI_table * psi,enum PSI_table_lock_operation op,ulong flags,const char * src_file,int src_line)112 inline_mysql_start_table_lock_wait(PSI_table_locker_state *state,
113                                    struct PSI_table *psi,
114                                    enum PSI_table_lock_operation op,
115                                    ulong flags, const char *src_file, int src_line)
116 {
117   if (psi != NULL)
118   {
119     struct PSI_table_locker *locker;
120     locker= PSI_TABLE_CALL(start_table_lock_wait)
121       (state, psi, op, flags, src_file, src_line);
122     return locker;
123   }
124   return NULL;
125 }
126 
127 /**
128   Instrumentation calls for MYSQL_END_TABLE_LOCK_WAIT.
129   @sa MYSQL_START_TABLE_LOCK_WAIT.
130 */
131 static inline void
inline_mysql_end_table_lock_wait(struct PSI_table_locker * locker)132 inline_mysql_end_table_lock_wait(struct PSI_table_locker *locker)
133 {
134   if (locker != NULL)
135     PSI_TABLE_CALL(end_table_lock_wait)(locker);
136 }
137 
138 static inline void
inline_mysql_unlock_table(struct PSI_table * table)139 inline_mysql_unlock_table(struct PSI_table *table)
140 {
141   if (table != NULL)
142     PSI_TABLE_CALL(unlock_table)(table);
143 }
144 #endif
145 
146 /** @} (end of group Table_instrumentation) */
147 
148 #endif
149 
150