1 /* Copyright (c) 2013, 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
21   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #ifndef MYSQL_SP_H
24 #define MYSQL_SP_H
25 
26 /**
27   @file mysql/psi/mysql_sp.h
28   Instrumentation helpers for stored programs.
29 */
30 
31 #include "mysql/psi/psi.h"
32 
33 #ifndef PSI_SP_CALL
34 #define PSI_SP_CALL(M) PSI_DYNAMIC_CALL(M)
35 #endif
36 
37 #ifdef HAVE_PSI_SP_INTERFACE
38   #define MYSQL_START_SP(STATE, SP_SHARE) \
39     inline_mysql_start_sp(STATE, SP_SHARE)
40 #else
41   #define MYSQL_START_SP(STATE, SP_SHARE) \
42     NULL
43 #endif
44 
45 
46 #ifdef HAVE_PSI_SP_INTERFACE
47   #define MYSQL_END_SP(LOCKER) \
48     inline_mysql_end_sp(LOCKER)
49 #else
50   #define MYSQL_END_SP(LOCKER) \
51     do {} while (0)
52 #endif
53 
54 #ifdef HAVE_PSI_SP_INTERFACE
55   #define MYSQL_DROP_SP(OT, SN, SNL, ON, ONL) \
56     inline_mysql_drop_sp(OT, SN, SNL, ON, ONL)
57 #else
58   #define MYSQL_DROP_SP(OT, SN, SNL, ON, ONL) \
59     do {} while (0)
60 #endif
61 
62 #ifdef HAVE_PSI_SP_INTERFACE
63   #define MYSQL_GET_SP_SHARE(OT, SN, SNL, ON, ONL) \
64     inline_mysql_get_sp_share(OT, SN, SNL, ON, ONL)
65 #else
66   #define MYSQL_GET_SP_SHARE(OT, SN, SNL, ON, ONL) \
67     NULL
68 #endif
69 
70 #ifdef HAVE_PSI_SP_INTERFACE
71 static inline struct PSI_sp_locker*
inline_mysql_start_sp(PSI_sp_locker_state * state,PSI_sp_share * sp_share)72 inline_mysql_start_sp(PSI_sp_locker_state *state, PSI_sp_share *sp_share)
73 {
74   return PSI_SP_CALL(start_sp)(state, sp_share);
75 }
76 
inline_mysql_end_sp(PSI_sp_locker * locker)77 static inline void inline_mysql_end_sp(PSI_sp_locker *locker)
78 {
79   if (likely(locker != NULL))
80     PSI_SP_CALL(end_sp)(locker);
81 }
82 
83 static inline void
inline_mysql_drop_sp(uint sp_type,const char * schema_name,uint shcema_name_length,const char * object_name,uint object_name_length)84 inline_mysql_drop_sp(uint sp_type,
85                      const char* schema_name, uint shcema_name_length,
86                      const char* object_name, uint object_name_length)
87 {
88   PSI_SP_CALL(drop_sp)(sp_type,
89                        schema_name, shcema_name_length,
90                        object_name, object_name_length);
91 }
92 
93 static inline PSI_sp_share*
inline_mysql_get_sp_share(uint sp_type,const char * schema_name,uint shcema_name_length,const char * object_name,uint object_name_length)94 inline_mysql_get_sp_share(uint sp_type,
95                           const char* schema_name, uint shcema_name_length,
96                           const char* object_name, uint object_name_length)
97 {
98   return PSI_SP_CALL(get_sp_share)(sp_type,
99                                    schema_name, shcema_name_length,
100                                    object_name, object_name_length);
101 }
102 #endif
103 
104 #endif
105