2020 along with this program; if not, write to the Free Software
2121 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2222
23+ #include " mutex_lock.h"
2324#include " my_dbug.h" /* DBUG_ASSERT */
2425#include " mysql/components/services/log_builtins.h" /* LogErr */
2526#include " mysql/status_var.h" /* SHOW_VAR */
@@ -32,19 +33,19 @@ Ssl_acceptor_context_container *mysql_main;
3233Ssl_acceptor_context_container *mysql_admin;
3334
3435Ssl_acceptor_context_container::Ssl_acceptor_context_container (
35- Ssl_acceptor_context_data * data)
36- : lock_( nullptr ) {
37- lock_ = new Ssl_acceptor_context_data_lock (data );
36+ std::shared_ptr< Ssl_acceptor_context_data> && data)
37+ : data_(data ) {
38+ mysql_mutex_init (PSI_NOT_INSTRUMENTED, &mutex_, MY_MUTEX_INIT_FAST );
3839}
3940
4041Ssl_acceptor_context_container ::~Ssl_acceptor_context_container () {
41- if (lock_ != nullptr ) delete lock_;
42- lock_ = nullptr ;
42+ mysql_mutex_destroy (&mutex_);
4343}
4444
4545void Ssl_acceptor_context_container::switch_data (
46- Ssl_acceptor_context_data *new_data) {
47- if (lock_ != nullptr ) lock_->write_wait_and_delete (new_data);
46+ std::shared_ptr<Ssl_acceptor_context_data> &&new_data) {
47+ MUTEX_LOCK (lock, &mutex_);
48+ data_ = new_data;
4849}
4950
5051bool TLS_channel::singleton_init (Ssl_acceptor_context_container **out,
@@ -67,10 +68,10 @@ bool TLS_channel::singleton_init(Ssl_acceptor_context_container **out,
6768 in auto-generation, bad key material explicitly specified or
6869 auto-generation disabled explcitly while SSL is still on.
6970 */
70- Ssl_acceptor_context_data * news =
71- new Ssl_acceptor_context_data (channel, use_ssl_arg, callbacks);
71+ auto news = std::make_shared<Ssl_acceptor_context_data>(channel, use_ssl_arg,
72+ callbacks);
7273 Ssl_acceptor_context_container *new_container =
73- new Ssl_acceptor_context_container (news);
74+ new Ssl_acceptor_context_container (std::move ( news) );
7475 if (news == nullptr || new_container == nullptr ) {
7576 LogErr (WARNING_LEVEL, ER_SSL_LIBRARY_ERROR,
7677 " Error initializing the SSL context system structure" );
@@ -101,29 +102,35 @@ void TLS_channel::singleton_flush(Ssl_acceptor_context_container *container,
101102 Ssl_init_callback *callbacks,
102103 enum enum_ssl_init_error *error, bool force) {
103104 if (container == nullptr ) return ;
104- Ssl_acceptor_context_data * news =
105- new Ssl_acceptor_context_data ( channel, true , callbacks, false , error);
105+ auto news = std::make_shared<Ssl_acceptor_context_data>(
106+ channel, true , callbacks, false , error);
106107 if (*error != SSL_INITERR_NOERROR && !force) {
107- delete news;
108108 return ;
109109 }
110- (void )container->switch_data (news);
110+ (void )container->switch_data (std::move ( news) );
111111 return ;
112112}
113113
114+ Lock_and_access_ssl_acceptor_context::Lock_and_access_ssl_acceptor_context (
115+ Ssl_acceptor_context_container *context) {
116+ // Take a reference
117+ MUTEX_LOCK (lock, &context->mutex_ );
118+ data_ = context->data_ ;
119+ }
120+
114121std::string Lock_and_access_ssl_acceptor_context::show_property (
115122 Ssl_acceptor_context_property_type property_type) {
116- const Ssl_acceptor_context_data *data = read_lock_ ;
123+ const Ssl_acceptor_context_data *data = data_. get () ;
117124 return (data != nullptr ? data->show_property (property_type) : std::string{});
118125}
119126
120127std::string Lock_and_access_ssl_acceptor_context::channel_name () {
121- const Ssl_acceptor_context_data *data = read_lock_ ;
128+ const Ssl_acceptor_context_data *data = data_. get () ;
122129 return (data != nullptr ? data->channel_name () : std::string{});
123130}
124131
125132bool Lock_and_access_ssl_acceptor_context::have_ssl () {
126- const Ssl_acceptor_context_data *data = read_lock_ ;
133+ const Ssl_acceptor_context_data *data = data_. get () ;
127134 return (data != nullptr ? data->have_ssl () : false );
128135}
129136
0 commit comments