MySQL 8.0.39
Source Code Documentation
channel.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 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#include <atomic>
24#include <map>
25#include <set>
26#include <string>
27#include "cache_allocator.h"
29
30namespace reference_caching {
31
33 public:
34 static channel_imp *create(service_names_set<> &service_names);
35 static bool destroy(channel_imp *channel);
36 static bool factory_init();
37 static bool factory_deinit();
38 static channel_imp *channel_by_name(std::string service_name);
39
40 bool is_valid() { return m_valid; }
41 void set_valid(bool new_value) {
42 m_valid.store(new_value, std::memory_order_relaxed);
43 }
44
46
48 bool ignore_list_add(std::string service_implementation);
49 bool ignore_list_remove(std::string service_implementation);
50 bool ignore_list_clear();
51
52 bool is_alone() { return m_reference_count == 1; }
54 m_reference_count.fetch_add(1, std::memory_order_relaxed);
55 return this;
56 }
57 int unref() {
58 return m_reference_count.fetch_sub(1, std::memory_order_relaxed);
59 }
61 : m_has_ignore_list(false), m_valid{true}, m_reference_count{0} {
62 m_service_names = service_names;
63 }
64 ~channel_imp() = default;
65
66 bool operator==(channel_imp &other) const {
67 return m_service_names == other.m_service_names;
68 }
69
70 private:
71 // disable copy constructors
74
77 std::atomic<bool> m_has_ignore_list;
78 std::atomic<bool> m_valid;
79 std::atomic<int> m_reference_count;
80};
81
82} // namespace reference_caching
Definition: cache_allocator.h:31
Definition: channel.h:32
static channel_imp * create(service_names_set<> &service_names)
Definition: channel.cc:44
static bool factory_deinit()
Definition: channel.cc:109
void set_valid(bool new_value)
Definition: channel.h:41
std::atomic< bool > m_has_ignore_list
Definition: channel.h:77
bool operator==(channel_imp &other) const
Definition: channel.h:66
channel_imp * ref()
Definition: channel.h:53
static bool destroy(channel_imp *channel)
Definition: channel.cc:70
channel_imp & operator=(const channel_imp &)
service_names_set & get_service_names()
Definition: channel.h:45
channel_imp(const channel_imp &)
bool is_valid()
Definition: channel.h:40
channel_imp(service_names_set<> &service_names)
Definition: channel.h:60
static bool factory_init()
Definition: channel.cc:91
bool ignore_list_add(std::string service_implementation)
Definition: channel.cc:144
static channel_imp * channel_by_name(std::string service_name)
Definition: channel.cc:125
service_names_set m_ignore_list
Definition: channel.h:76
int unref()
Definition: channel.h:57
service_names_set m_service_names
Definition: channel.h:75
bool is_alone()
Definition: channel.h:52
void ignore_list_copy(service_names_set<> &dest_set)
Definition: channel.cc:136
bool ignore_list_remove(std::string service_implementation)
Definition: channel.cc:152
std::atomic< bool > m_valid
Definition: channel.h:78
bool ignore_list_clear()
Definition: channel.cc:163
std::atomic< int > m_reference_count
Definition: channel.h:79
Definition: reference_cache_common.h:37
Definition: cache.cc:29
Definition: task.h:427