1 /* Copyright (c) 2010, 2021, Oracle and/or its affiliates.
2 
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 
7    This program is also distributed with certain software (including
8    but not limited to OpenSSL) that is licensed under separate terms,
9    as designated in a particular file or component or in included license
10    documentation.  The authors of MySQL hereby grant you an additional
11    permission to link the program and your derivative works with the
12    separately licensed software that they have included with MySQL.
13 
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License, version 2.0, for more details.
18 
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #include "rpl_info.h"
24 
25 #include "m_string.h"      // strmake
26 
Rpl_info(const char * type,PSI_mutex_key * param_key_info_run_lock,PSI_mutex_key * param_key_info_data_lock,PSI_mutex_key * param_key_info_sleep_lock,PSI_mutex_key * param_key_info_thd_lock,PSI_mutex_key * param_key_info_data_cond,PSI_mutex_key * param_key_info_start_cond,PSI_mutex_key * param_key_info_stop_cond,PSI_mutex_key * param_key_info_sleep_cond,uint param_id,const char * param_channel)27 Rpl_info::Rpl_info(const char* type
28 #ifdef HAVE_PSI_INTERFACE
29                    ,PSI_mutex_key *param_key_info_run_lock,
30                    PSI_mutex_key *param_key_info_data_lock,
31                    PSI_mutex_key *param_key_info_sleep_lock,
32                    PSI_mutex_key *param_key_info_thd_lock,
33                    PSI_mutex_key *param_key_info_data_cond,
34                    PSI_mutex_key *param_key_info_start_cond,
35                    PSI_mutex_key *param_key_info_stop_cond,
36                    PSI_mutex_key *param_key_info_sleep_cond
37 #endif
38                    ,uint param_id, const char *param_channel
39                  )
40   :Slave_reporting_capability(type),
41 #ifdef HAVE_PSI_INTERFACE
42   key_info_run_lock(param_key_info_run_lock),
43   key_info_data_lock(param_key_info_data_lock),
44   key_info_sleep_lock(param_key_info_sleep_lock),
45   key_info_thd_lock(param_key_info_thd_lock),
46   key_info_data_cond(param_key_info_data_cond),
47   key_info_start_cond(param_key_info_start_cond),
48   key_info_stop_cond(param_key_info_stop_cond),
49   key_info_sleep_cond(param_key_info_sleep_cond),
50 #endif
51   info_thd(0), inited(0), abort_slave(0),
52   slave_running(0), slave_run_id(0),
53   handler(0), internal_id(param_id)
54 {
55 #ifdef HAVE_PSI_INTERFACE
56   mysql_mutex_init(*key_info_run_lock,
57                     &run_lock, MY_MUTEX_INIT_FAST);
58   mysql_mutex_init(*key_info_data_lock,
59                    &data_lock, MY_MUTEX_INIT_FAST);
60   mysql_mutex_init(*key_info_sleep_lock,
61                     &sleep_lock, MY_MUTEX_INIT_FAST);
62   mysql_mutex_init(*key_info_thd_lock,
63                     &info_thd_lock, MY_MUTEX_INIT_FAST);
64   mysql_cond_init(*key_info_data_cond, &data_cond);
65   mysql_cond_init(*key_info_start_cond, &start_cond);
66   mysql_cond_init(*key_info_stop_cond, &stop_cond);
67   mysql_cond_init(*key_info_sleep_cond, &sleep_cond);
68 #else
69   mysql_mutex_init(NULL, &run_lock, MY_MUTEX_INIT_FAST);
70   mysql_mutex_init(NULL, &data_lock, MY_MUTEX_INIT_FAST);
71   mysql_mutex_init(NULL, &sleep_lock, MY_MUTEX_INIT_FAST);
72   mysql_mutex_init(NULL, &info_thd_lock, MY_MUTEX_INIT_FAST);
73   mysql_cond_init(NULL, &data_cond);
74   mysql_cond_init(NULL, &start_cond);
75   mysql_cond_init(NULL, &stop_cond);
76   mysql_cond_init(NULL, &sleep_cond);
77 #endif
78 
79   if (param_channel)
80     strmake(channel, param_channel, sizeof(channel) -1);
81   else
82     /*create a default empty channel*/
83     strmake(channel, "", sizeof(channel) -1);
84 
85   is_stopping.atomic_set(0);
86 }
87 
~Rpl_info()88 Rpl_info::~Rpl_info()
89 {
90   delete handler;
91 
92   mysql_mutex_destroy(&run_lock);
93   mysql_mutex_destroy(&data_lock);
94   mysql_mutex_destroy(&sleep_lock);
95   mysql_mutex_destroy(&info_thd_lock);
96   mysql_cond_destroy(&data_cond);
97   mysql_cond_destroy(&start_cond);
98   mysql_cond_destroy(&stop_cond);
99   mysql_cond_destroy(&sleep_cond);
100 }
101