1 /* Copyright (c) 2012, 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_MDL_H
24 #define MYSQL_MDL_H
25
26 /**
27 @file mysql/psi/mysql_mdl.h
28 Instrumentation helpers for metadata locks.
29 */
30
31 #include "mysql/psi/psi.h"
32
33 #ifndef PSI_METADATA_CALL
34 #define PSI_METADATA_CALL(M) PSI_DYNAMIC_CALL(M)
35 #endif
36
37 /**
38 @defgroup Thread_instrumentation Metadata Instrumentation
39 @ingroup Instrumentation_interface
40 @{
41 */
42
43 /**
44 @def mysql_mdl_create(K, M, A)
45 Instrumented metadata lock creation.
46 @param I Metadata lock identity
47 @param K Metadata key
48 @param T Metadata lock type
49 @param D Metadata lock duration
50 @param S Metadata lock status
51 @param F request source file
52 @param L request source line
53 */
54
55 #ifdef HAVE_PSI_METADATA_INTERFACE
56 #define mysql_mdl_create(I, K, T, D, S, F, L) \
57 inline_mysql_mdl_create(I, K, T, D, S, F, L)
58 #else
59 #define mysql_mdl_create(I, K, T, D, S, F, L) NULL
60 #endif
61
62 #ifdef HAVE_PSI_METADATA_INTERFACE
63 #define mysql_mdl_set_status(L, S) \
64 inline_mysql_mdl_set_status(L, S)
65 #else
66 #define mysql_mdl_set_status(L, S) \
67 do {} while (0)
68 #endif
69
70
71 /**
72 @def mysql_mdl_destroy(M)
73 Instrumented metadata lock destruction.
74 @param M Metadata lock
75 */
76 #ifdef HAVE_PSI_METADATA_INTERFACE
77 #define mysql_mdl_destroy(M) \
78 inline_mysql_mdl_destroy(M, __FILE__, __LINE__)
79 #else
80 #define mysql_mdl_destroy(M) \
81 do {} while (0)
82 #endif
83
84 #ifdef HAVE_PSI_METADATA_INTERFACE
85
86 static inline PSI_metadata_lock *
inline_mysql_mdl_create(void * identity,const MDL_key * mdl_key,enum_mdl_type mdl_type,enum_mdl_duration mdl_duration,MDL_ticket::enum_psi_status mdl_status,const char * src_file,uint src_line)87 inline_mysql_mdl_create(void *identity,
88 const MDL_key *mdl_key,
89 enum_mdl_type mdl_type,
90 enum_mdl_duration mdl_duration,
91 MDL_ticket::enum_psi_status mdl_status,
92 const char *src_file, uint src_line)
93 {
94 PSI_metadata_lock *result;
95
96 /* static_cast: Fit a round C++ enum peg into a square C int hole ... */
97 result= PSI_METADATA_CALL(create_metadata_lock)
98 (identity,
99 mdl_key,
100 static_cast<opaque_mdl_type> (mdl_type),
101 static_cast<opaque_mdl_duration> (mdl_duration),
102 static_cast<opaque_mdl_status> (mdl_status),
103 src_file, src_line);
104
105 return result;
106 }
107
inline_mysql_mdl_set_status(PSI_metadata_lock * psi,MDL_ticket::enum_psi_status mdl_status)108 static inline void inline_mysql_mdl_set_status(
109 PSI_metadata_lock *psi,
110 MDL_ticket::enum_psi_status mdl_status)
111 {
112 if (psi != NULL)
113 PSI_METADATA_CALL(set_metadata_lock_status)(psi, mdl_status);
114 }
115
inline_mysql_mdl_destroy(PSI_metadata_lock * psi,const char * src_file,uint src_line)116 static inline void inline_mysql_mdl_destroy(
117 PSI_metadata_lock *psi,
118 const char *src_file, uint src_line)
119 {
120 if (psi != NULL)
121 PSI_METADATA_CALL(destroy_metadata_lock)(psi);
122 }
123 #endif /* HAVE_PSI_METADATA_INTERFACE */
124
125 /** @} (end of group Metadata_instrumentation) */
126
127 #endif
128
129