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