MySQL 8.4.2
Source Code Documentation
registry_no_lock_imp.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_SERVER_REGISTRY_NO_LOCK_H
25#define MYSQL_SERVER_REGISTRY_NO_LOCK_H
26
30#include <map>
31#include <memory>
32
33#include "c_string_less.h"
35
36typedef std::map<const char *, mysql_service_implementation *, c_string_less>
38
40 protected:
41 typedef std::map<my_h_service, mysql_service_implementation *>
43
44 /* contain the actual fields definitions */
47
48 public:
49 /**
50 De-initializes registry, other structures.
51 */
52 static void deinit();
53
54 /**
55 Gets current reference count for a Service Implementation related to the
56 specified pointer to the interface structure. Assumes caller has at least
57 a read lock on the Registry.
58
59 @param interface A pointer to the interface structure of the Service
60 Implementation to get reference count of.
61 @return A current reference count for specified Service Implementation.
62 Returns 0 in case there is no such interface or it is not referenced.
63 */
65 my_h_service interface);
66
67 /**
68 Finds and acquires a Service by name. A name of the Service or the Service
69 Implementation can be specified. In case of the Service name, the default
70 Service Implementation for Service specified will be returned. Assumes
71 caller has at least a read lock on the Registry.
72
73 @param service_name Name of Service or Service Implementation to acquire.
74 @param [out] out_service Pointer to Service handle to set acquired Service.
75 @return Status of performed operation
76 @retval false success
77 @retval true failure
78 */
79 static bool acquire_nolock(const char *service_name,
80 my_h_service *out_service);
81
82 /**
83 Releases the Service Implementation previously acquired. After the call to
84 this method the usage of the Service Implementation handle will lead to
85 unpredicted results. Assumes caller has at least a read lock on the
86 Registry.
87
88 @param service Service Implementation handle of already acquired Service.
89 @return Status of performed operation
90 @retval false success
91 @retval true failure
92 */
93 static bool release_nolock(my_h_service service);
94
95 /**
96 Registers a new Service Implementation. If it is the first Service
97 Implementation for the specified Service then it is made a default one.
98 Assumes caller has a write lock on the Registry.
99
100 @param service_implementation_name Name of the Service Implementation to
101 register.
102 @param ptr Pointer to the Service Implementation structure.
103 @return Status of performed operation
104 @retval false success
105 @retval true failure
106 */
107 static bool register_service_nolock(const char *service_implementation_name,
108 my_h_service ptr);
109
110 /**
111 Removes previously registered Service Implementation from registry. If it is
112 the default one for specified Service then any one still registered is made
113 default. If there is no other, the default entry is removed from the
114 Registry too. Assumes caller has a write lock on the Registry.
115
116 @param service_implementation_name Name of the Service Implementation to
117 unregister.
118 @return Status of performed operation
119 @retval false success
120 @retval true Failure. May happen when Service is still being referenced.
121 */
122 static bool unregister_nolock(const char *service_implementation_name);
123
124 /* Service Implementations */
125 /**
126 Finds and acquires a Service by name. A name of the Service or the Service
127 Implementation can be specified. In case of the Service name, the default
128 Service Implementation for Service specified will be returned.
129
130 This does not take any lock on the registry. It must not be used unless
131 absolutely necessary. Use the mysql_registry_imp version instead.
132
133 @param service_name Name of Service or Service Implementation to acquire.
134 @param [out] out_service Pointer to Service handle to set acquired Service.
135 @return Status of performed operation
136 @retval false success
137 @retval true failure
138 */
139 static DEFINE_BOOL_METHOD(acquire, (const char *service_name,
140 my_h_service *out_service));
141
142 /**
143 Finds a Service by name. If there is a Service Implementation with the same
144 Component part of name as the input Service then the found Service is
145 returned.
146
147 This does not take any lock on the registry. It must not be used unless
148 absolutely necessary. Use the mysql_registry_imp version instead.
149
150 @param service_name Name of Service or Service Implementation to acquire.
151 @param service Service handle already acquired Service Implementation.
152 @param [out] out_service Pointer to Service Implementation handle to set
153 acquired Service Implementation.
154 @return Status of performed operation
155 @retval false success
156 @retval true failure
157 */
159 (const char *service_name, my_h_service service,
160 my_h_service *out_service));
161
162 /**
163 Releases the Service Implementation previously acquired. After the call to
164 this method the usage of the Service Implementation handle will lead to
165 unpredicted results.
166
167 This does not take any lock on the registry. It must not be used unless
168 absolutely necessary. Use the mysql_registry_imp version instead.
169
170 @param service Service Implementation handle of already acquired Service.
171 @return Status of performed operation
172 @retval false success
173 @retval true failure
174 */
175 static DEFINE_BOOL_METHOD(release, (my_h_service service));
176
177 /**
178 Registers a new Service Implementation. If it is the first Service
179 Implementation for the specified Service then it is made a default one.
180
181 This does not take any lock on the registry. It must not be used unless
182 absolutely necessary. Use the mysql_registry_imp version instead.
183
184 @param service_implementation_name Name of the Service Implementation to
185 register.
186 @param ptr Pointer to the Service Implementation structure.
187 @return Status of performed operation
188 @retval false success
189 @retval true failure
190 */
192 (const char *service_implementation_name,
193 my_h_service ptr));
194
195 /**
196 Removes previously registered Service Implementation from registry. If it is
197 the default one for specified Service then any one still registered is made
198 default. If there is no other, the default entry is removed from the
199 Registry too.
200
201 This does not take any lock on the registry. It must not be used unless
202 absolutely necessary. Use the mysql_registry_imp version instead.
203
204 @param service_implementation_name Name of the Service Implementation to
205 unregister.
206 @return Status of performed operation
207 @retval false success
208 @retval true Failure. May happen when Service is still being referenced.
209 */
211 (const char *service_implementation_name));
212
213 /**
214 Sets new default Service Implementation for corresponding Service name.
215
216 This does not take any lock on the registry. It must not be used unless
217 absolutely necessary. Use the mysql_registry_imp version instead.
218
219 @param service_implementation_name Name of the Service Implementation to
220 set as default one.
221 @return Status of performed operation
222 @retval false success
223 @retval true failure
224 */
226 (const char *service_implementation_name));
227
228 private:
229 /**
230 Finds a Service Implementation data structure based on the pointer to
231 interface struct supplied. Assumes caller has at least a read lock on the
232 Registry.
233
234 @param interface A pointer to the interface structure of the Service
235 Implementation to look for.
236 @return A pointer to respective Service Implementation data structure, or
237 NULL if no such interface pointer is registered within the Registry.
238 */
240 my_h_service interface);
241};
242#endif /* MYSQL_SERVER_REGISTRY_NO_LOCK_H */
Definition: registry_no_lock_imp.h:39
static my_service_registry service_registry
Definition: registry_no_lock_imp.h:45
static bool acquire_nolock(const char *service_name, my_h_service *out_service)
Finds and acquires a Service by name.
Definition: registry_no_lock.cc:99
static mysql_service_status_t acquire_related(const char *service_name, my_h_service service, my_h_service *out_service) noexcept
Finds a Service by name.
Definition: registry_no_lock.cc:318
static bool release_nolock(my_h_service service)
Releases the Service Implementation previously acquired.
Definition: registry_no_lock.cc:132
static mysql_service_implementation * get_service_implementation_by_interface(my_h_service interface)
Finds a Service Implementation data structure based on the pointer to interface struct supplied.
Definition: registry_no_lock.cc:55
static mysql_service_status_t unregister(const char *service_implementation_name) noexcept
Removes previously registered Service Implementation from registry.
Definition: registry_no_lock.cc:405
static mysql_service_status_t register_service(const char *service_implementation_name, my_h_service ptr) noexcept
Registers a new Service Implementation.
Definition: registry_no_lock.cc:384
static mysql_service_status_t release(my_h_service service) noexcept
Releases the Service Implementation previously acquired.
Definition: registry_no_lock.cc:364
static uint64_t get_service_implementation_reference_count(my_h_service interface)
Gets current reference count for a Service Implementation related to the specified pointer to the int...
Definition: registry_no_lock.cc:76
static mysql_service_status_t acquire(const char *service_name, my_h_service *out_service) noexcept
Finds and acquires a Service by name.
Definition: registry_no_lock.cc:296
std::map< my_h_service, mysql_service_implementation * > my_interface_mapping
Definition: registry_no_lock_imp.h:42
static my_interface_mapping interface_mapping
Definition: registry_no_lock_imp.h:46
static bool register_service_nolock(const char *service_implementation_name, my_h_service ptr)
Registers a new Service Implementation.
Definition: registry_no_lock.cc:162
static void deinit()
De-initializes registry, other structures.
Definition: registry_no_lock.cc:39
static bool unregister_nolock(const char *service_implementation_name)
Removes previously registered Service Implementation from registry.
Definition: registry_no_lock.cc:221
static mysql_service_status_t set_default(const char *service_implementation_name) noexcept
Sets new default Service Implementation for corresponding Service name.
Definition: registry_no_lock.cc:423
a Service implementation registry data
Definition: mysql_service_implementation.h:32
struct my_h_service_imp * my_h_service
A handle type for acquired Service.
Definition: registry.h:33
std::map< const char *, mysql_service_implementation *, c_string_less > my_service_registry
Definition: registry_no_lock.cc:34
std::map< const char *, mysql_service_implementation *, c_string_less > my_service_registry
Definition: registry_no_lock_imp.h:37
Specifies macros to define Service Implementations.
#define DEFINE_BOOL_METHOD(name, args)
A short macro to define method that returns bool, which is the most common case.
Definition: service_implementation.h:88