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