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