mysql_mdl.h 3.6 KB

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