service_locking.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
  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. This program is also distributed with certain software (including
  7. but not limited to OpenSSL) that is licensed under separate terms,
  8. as designated in a particular file or component or in included license
  9. documentation. The authors of MySQL hereby grant you an additional
  10. permission to link the program and your derivative works with the
  11. separately licensed software that they have included with MySQL.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License, version 2.0, for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef SERVICE_LOCKING_INCLUDED
  21. #define SERVICE_LOCKING_INCLUDED
  22. /*
  23. This service provides support for taking read/write locks.
  24. It is intended for use with fabric, but it is still a general
  25. service. The locks are in a separate namespace from other
  26. locks in the server, and there is also no interactions with
  27. transactions (i.e. locks are not released on commit/abort).
  28. These locks are implemented using the metadata lock (MDL) subsystem
  29. and thus deadlocks involving locking service locks and other types
  30. of metadata will be detected using the MDL deadlock detector.
  31. */
  32. #ifdef __cplusplus
  33. class THD;
  34. #define MYSQL_THD THD*
  35. #else
  36. #define MYSQL_THD void*
  37. #endif
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /**
  42. Types of locking service locks.
  43. LOCKING_SERVICE_READ is compatible with LOCKING_SERVICE_READ.
  44. All other combinations are incompatible.
  45. */
  46. enum enum_locking_service_lock_type
  47. { LOCKING_SERVICE_READ, LOCKING_SERVICE_WRITE };
  48. extern struct mysql_locking_service_st {
  49. /**
  50. Acquire locking service locks.
  51. @param opaque_thd Thread handle. If NULL, current_thd will be used.
  52. @param lock_namespace Namespace of the locks to acquire.
  53. @param lock_names Array of names of the locks to acquire.
  54. @param lock_num Number of elements in 'lock_names'.
  55. @param lock_type Lock type to acquire. LOCKING_SERVICE_READ or _WRITE.
  56. @param lock_timeout Number of seconds to wait before giving up.
  57. @retval 1 Acquisition failed, error has been reported.
  58. @retval 0 Acquisition successful, all locks acquired.
  59. @note both lock_namespace and lock_names are limited to 64 characters max.
  60. Names are compared using binary comparison.
  61. */
  62. int (*mysql_acquire_locks)(MYSQL_THD opaque_thd, const char* lock_namespace,
  63. const char**lock_names, size_t lock_num,
  64. enum enum_locking_service_lock_type lock_type,
  65. unsigned long lock_timeout);
  66. /**
  67. Release all lock service locks taken by the given connection
  68. in the given namespace.
  69. @param opaque_thd Thread handle. If NULL, current_thd will be used.
  70. @param lock_namespace Namespace of the locks to release.
  71. @retval 1 Release failed, error has been reported.
  72. @retval 0 Release successful, all locks acquired.
  73. */
  74. int (*mysql_release_locks)(MYSQL_THD opaque_thd, const char* lock_namespace);
  75. } *mysql_locking_service;
  76. #ifdef MYSQL_DYNAMIC_PLUGIN
  77. #define mysql_acquire_locking_service_locks(_THD, _NAMESPACE, _NAMES, _NUM, \
  78. _TYPE, _TIMEOUT) \
  79. mysql_locking_service->mysql_acquire_locks(_THD, _NAMESPACE, _NAMES, _NUM, \
  80. _TYPE, _TIMEOUT)
  81. #define mysql_release_locking_service_locks(_THD, _NAMESPACE) \
  82. mysql_locking_service->mysql_release_locks(_THD, _NAMESPACE)
  83. #else
  84. int mysql_acquire_locking_service_locks(MYSQL_THD opaque_thd,
  85. const char* lock_namespace,
  86. const char**lock_names,
  87. size_t lock_num,
  88. enum enum_locking_service_lock_type lock_type,
  89. unsigned long lock_timeout);
  90. int mysql_release_locking_service_locks(MYSQL_THD opaque_thd,
  91. const char* lock_namespace);
  92. #endif /* MYSQL_DYNAMIC_PLUGIN */
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif /* SERVICE_LOCKING_INCLUDED */