1 /* Copyright (c) 2015, 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 Foundation,
21 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22
23 #include "channel_observation_manager.h"
24 #include "observer_server_channels.h"
25 #include "plugin_psi.h"
26
27
~Channel_state_observer()28 Channel_state_observer::~Channel_state_observer() {}
29
30 Channel_observation_manager::
Channel_observation_manager(MYSQL_PLUGIN plugin_info)31 Channel_observation_manager(MYSQL_PLUGIN plugin_info)
32 :group_replication_plugin_info(plugin_info)
33 {
34 channel_list_lock= new Checkable_rwlock(
35 #ifdef HAVE_PSI_INTERFACE
36 key_GR_LOCK_channel_observation_list
37 #endif
38 );
39
40 server_channel_state_observers= binlog_IO_observer;
41 register_binlog_relay_io_observer(&server_channel_state_observers,
42 group_replication_plugin_info);
43 }
44
~Channel_observation_manager()45 Channel_observation_manager::~Channel_observation_manager()
46 {
47 if(!channel_observers.empty())
48 {
49 /* purecov: begin inspected */
50 std::list<Channel_state_observer*>::const_iterator obs_iterator;
51 for (obs_iterator = channel_observers.begin();
52 obs_iterator != channel_observers.end();
53 ++obs_iterator)
54 {
55 delete (*obs_iterator);
56 }
57 channel_observers.clear();
58 /* purecov: end */
59 }
60 unregister_binlog_relay_io_observer(&server_channel_state_observers,
61 group_replication_plugin_info);
62
63 delete channel_list_lock;
64 }
65
66 std::list<Channel_state_observer*>*
get_channel_state_observers()67 Channel_observation_manager::get_channel_state_observers()
68 {
69 DBUG_ENTER("Channel_observation_manager::get_channel_state_observers");
70 #ifndef NDEBUG
71 channel_list_lock->assert_some_lock();
72 #endif
73 DBUG_RETURN(&channel_observers);
74 }
75
76 void
77 Channel_observation_manager::
register_channel_observer(Channel_state_observer * observer)78 register_channel_observer(Channel_state_observer* observer)
79 {
80 DBUG_ENTER("Channel_observation_manager::register_channel_observer");
81 write_lock_channel_list();
82 channel_observers.push_back(observer);
83 unlock_channel_list();
84 DBUG_VOID_RETURN;
85 }
86
87 void
88 Channel_observation_manager::
unregister_channel_observer(Channel_state_observer * observer)89 unregister_channel_observer(Channel_state_observer* observer)
90 {
91 DBUG_ENTER("Channel_observation_manager::unregister_channel_observer");
92 write_lock_channel_list();
93 channel_observers.remove(observer);
94 unlock_channel_list();
95 DBUG_VOID_RETURN;
96 }
97
read_lock_channel_list()98 void Channel_observation_manager::read_lock_channel_list()
99 {
100 channel_list_lock->rdlock();
101 }
102
write_lock_channel_list()103 void Channel_observation_manager::write_lock_channel_list()
104 {
105 channel_list_lock->wrlock();
106 }
107
unlock_channel_list()108 void Channel_observation_manager::unlock_channel_list()
109 {
110 channel_list_lock->unlock();
111 }
112
113