mysql_table.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License, version 2.0,
  4. as published by the Free Software Foundation.
  5. This program is also distributed with certain software (including
  6. but not limited to OpenSSL) that is licensed under separate terms,
  7. as designated in a particular file or component or in included license
  8. documentation. The authors of MySQL hereby grant you an additional
  9. permission to link the program and your derivative works with the
  10. separately licensed software that they have included with MySQL.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU General Public License, version 2.0, for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software Foundation,
  17. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
  18. #ifndef MYSQL_TABLE_H
  19. #define MYSQL_TABLE_H
  20. /**
  21. @file mysql/psi/mysql_table.h
  22. Instrumentation helpers for table io.
  23. */
  24. #include "mysql/psi/psi.h"
  25. #ifndef PSI_TABLE_CALL
  26. #define PSI_TABLE_CALL(M) PSI_DYNAMIC_CALL(M)
  27. #endif
  28. /**
  29. @defgroup Table_instrumentation Table Instrumentation
  30. @ingroup Instrumentation_interface
  31. @{
  32. */
  33. /**
  34. @def MYSQL_TABLE_WAIT_VARIABLES
  35. Instrumentation helper for table waits.
  36. This instrumentation declares local variables.
  37. Do not use a ';' after this macro
  38. @param LOCKER the locker
  39. @param STATE the locker state
  40. @sa MYSQL_START_TABLE_IO_WAIT.
  41. @sa MYSQL_END_TABLE_IO_WAIT.
  42. @sa MYSQL_START_TABLE_LOCK_WAIT.
  43. @sa MYSQL_END_TABLE_LOCK_WAIT.
  44. */
  45. #ifdef HAVE_PSI_TABLE_INTERFACE
  46. #define MYSQL_TABLE_WAIT_VARIABLES(LOCKER, STATE) \
  47. struct PSI_table_locker* LOCKER; \
  48. PSI_table_locker_state STATE;
  49. #else
  50. #define MYSQL_TABLE_WAIT_VARIABLES(LOCKER, STATE)
  51. #endif
  52. /**
  53. @def MYSQL_START_TABLE_LOCK_WAIT
  54. Instrumentation helper for table lock waits.
  55. This instrumentation marks the start of a wait event.
  56. @param LOCKER the locker
  57. @param STATE the locker state
  58. @param PSI the instrumented table
  59. @param OP the table operation to be performed
  60. @param FLAGS per table operation flags.
  61. @sa MYSQL_END_TABLE_LOCK_WAIT.
  62. */
  63. #ifdef HAVE_PSI_TABLE_INTERFACE
  64. #define MYSQL_START_TABLE_LOCK_WAIT(LOCKER, STATE, PSI, OP, FLAGS) \
  65. LOCKER= inline_mysql_start_table_lock_wait(STATE, PSI, \
  66. OP, FLAGS, __FILE__, __LINE__)
  67. #else
  68. #define MYSQL_START_TABLE_LOCK_WAIT(LOCKER, STATE, PSI, OP, FLAGS) \
  69. do {} while (0)
  70. #endif
  71. /**
  72. @def MYSQL_END_TABLE_LOCK_WAIT
  73. Instrumentation helper for table lock waits.
  74. This instrumentation marks the end of a wait event.
  75. @param LOCKER the locker
  76. @sa MYSQL_START_TABLE_LOCK_WAIT.
  77. */
  78. #ifdef HAVE_PSI_TABLE_INTERFACE
  79. #define MYSQL_END_TABLE_LOCK_WAIT(LOCKER) \
  80. inline_mysql_end_table_lock_wait(LOCKER)
  81. #else
  82. #define MYSQL_END_TABLE_LOCK_WAIT(LOCKER) \
  83. do {} while (0)
  84. #endif
  85. #ifdef HAVE_PSI_TABLE_INTERFACE
  86. #define MYSQL_UNLOCK_TABLE(T) \
  87. inline_mysql_unlock_table(T)
  88. #else
  89. #define MYSQL_UNLOCK_TABLE(T) \
  90. do {} while (0)
  91. #endif
  92. #ifdef HAVE_PSI_TABLE_INTERFACE
  93. /**
  94. Instrumentation calls for MYSQL_START_TABLE_LOCK_WAIT.
  95. @sa MYSQL_END_TABLE_LOCK_WAIT.
  96. */
  97. static inline struct PSI_table_locker *
  98. inline_mysql_start_table_lock_wait(PSI_table_locker_state *state,
  99. struct PSI_table *psi,
  100. enum PSI_table_lock_operation op,
  101. ulong flags, const char *src_file, int src_line)
  102. {
  103. if (psi != NULL)
  104. {
  105. struct PSI_table_locker *locker;
  106. locker= PSI_TABLE_CALL(start_table_lock_wait)
  107. (state, psi, op, flags, src_file, src_line);
  108. return locker;
  109. }
  110. return NULL;
  111. }
  112. /**
  113. Instrumentation calls for MYSQL_END_TABLE_LOCK_WAIT.
  114. @sa MYSQL_START_TABLE_LOCK_WAIT.
  115. */
  116. static inline void
  117. inline_mysql_end_table_lock_wait(struct PSI_table_locker *locker)
  118. {
  119. if (locker != NULL)
  120. PSI_TABLE_CALL(end_table_lock_wait)(locker);
  121. }
  122. static inline void
  123. inline_mysql_unlock_table(struct PSI_table *table)
  124. {
  125. if (table != NULL)
  126. PSI_TABLE_CALL(unlock_table)(table);
  127. }
  128. #endif
  129. /** @} (end of group Table_instrumentation) */
  130. #endif