1 /* Copyright (c) 2011, 2012, 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 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 /**
34   @defgroup Idle_instrumentation Idle Instrumentation
35   @ingroup Instrumentation_interface
36   @{
37 */
38 
39 /**
40   @def MYSQL_START_IDLE_WAIT
41   Instrumentation helper for table io_waits.
42   This instrumentation marks the start of a wait event.
43   @param LOCKER the locker
44   @param STATE the locker state
45   @sa MYSQL_END_IDLE_WAIT.
46 */
47 #ifdef HAVE_PSI_IDLE_INTERFACE
48   #define MYSQL_START_IDLE_WAIT(LOCKER, STATE) \
49     LOCKER= inline_mysql_start_idle_wait(STATE, __FILE__, __LINE__)
50 #else
51   #define MYSQL_START_IDLE_WAIT(LOCKER, STATE) \
52     do {} while (0)
53 #endif
54 
55 /**
56   @def MYSQL_END_IDLE_WAIT
57   Instrumentation helper for idle waits.
58   This instrumentation marks the end of a wait event.
59   @param LOCKER the locker
60   @sa MYSQL_START_IDLE_WAIT.
61 */
62 #ifdef HAVE_PSI_IDLE_INTERFACE
63   #define MYSQL_END_IDLE_WAIT(LOCKER) \
64     inline_mysql_end_idle_wait(LOCKER)
65 #else
66   #define MYSQL_END_IDLE_WAIT(LOCKER) \
67     do {} while (0)
68 #endif
69 
70 #ifdef HAVE_PSI_IDLE_INTERFACE
71 /**
72   Instrumentation calls for MYSQL_START_IDLE_WAIT.
73   @sa MYSQL_END_IDLE_WAIT.
74 */
75 static inline struct PSI_idle_locker *
inline_mysql_start_idle_wait(PSI_idle_locker_state * state,const char * src_file,int src_line)76 inline_mysql_start_idle_wait(PSI_idle_locker_state *state,
77                              const char *src_file, int src_line)
78 {
79   struct PSI_idle_locker *locker;
80   locker= PSI_IDLE_CALL(start_idle_wait)(state, src_file, src_line);
81   return locker;
82 }
83 
84 /**
85   Instrumentation calls for MYSQL_END_IDLE_WAIT.
86   @sa MYSQL_START_IDLE_WAIT.
87 */
88 static inline void
inline_mysql_end_idle_wait(struct PSI_idle_locker * locker)89 inline_mysql_end_idle_wait(struct PSI_idle_locker *locker)
90 {
91   if (likely(locker != NULL))
92     PSI_IDLE_CALL(end_idle_wait)(locker);
93 }
94 #endif
95 
96 /** @} (end of group Idle_instrumentation) */
97 
98 #endif
99 
100