MySQL 8.4.0
Source Code Documentation
sql_plugin_ref.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_PLUGIN_REF_INCLUDED
25#define SQL_PLUGIN_REF_INCLUDED
26
27#include "lex_string.h"
28#include "my_alloc.h"
30#include "prealloced_array.h"
31
32class sys_var;
33struct st_mysql_plugin;
34struct st_plugin_dl;
35
41};
42
43/* A handle of a plugin */
44
46 LEX_CSTRING name{nullptr, 0};
49 uint state{0};
50 uint ref_count{0}; /* number of threads using the plugin */
51 void *data{nullptr}; /* plugin type specific, e.g. handlerton */
52 MEM_ROOT mem_root; /* memory for dynamic plugin structures */
53 sys_var *system_vars{nullptr}; /* server variables for this plugin */
55 PLUGIN_OFF}; /* OFF, ON, FORCE, F+PERMANENT */
56};
57
58/*
59 See intern_plugin_lock() for the explanation for the
60 conditionally defined plugin_ref type
61*/
62
63#ifdef NDEBUG
64typedef struct st_plugin_int *plugin_ref;
65
66inline st_mysql_plugin *plugin_decl(st_plugin_int *ref) { return ref->plugin; }
67inline st_plugin_dl *plugin_dlib(st_plugin_int *ref) { return ref->plugin_dl; }
68template <typename T>
69inline T plugin_data(st_plugin_int *ref) {
70 return static_cast<T>(ref->data);
71}
72inline LEX_CSTRING *plugin_name(st_plugin_int *ref) { return &(ref->name); }
73inline uint plugin_state(st_plugin_int *ref) { return ref->state; }
75 return ref->load_option;
76}
77inline bool plugin_equals(st_plugin_int *ref1, st_plugin_int *ref2) {
78 return ref1 == ref2;
79}
80
81#else
82
83typedef struct st_plugin_int **plugin_ref;
84
86 return ref[0]->plugin;
87}
89 return ref[0]->plugin_dl;
90}
91template <typename T>
93 return static_cast<T>(ref[0]->data);
94}
95inline LEX_CSTRING *plugin_name(st_plugin_int **ref) { return &(ref[0]->name); }
96inline uint plugin_state(st_plugin_int **ref) { return ref[0]->state; }
98 return ref[0]->load_option;
99}
100inline bool plugin_equals(st_plugin_int **ref1, st_plugin_int **ref2) {
101 return ref1 && ref2 && (ref1[0] == ref2[0]);
102}
103#endif
104
105/**
106 @class Plugin_array
107
108 @brief Plugin array helper class.
109*/
110class Plugin_array : public Prealloced_array<plugin_ref, 2> {
111 public:
112 /**
113 Class construction.
114
115 @param psi_key PSI key.
116 */
117 explicit Plugin_array(PSI_memory_key psi_key)
118 : Prealloced_array<plugin_ref, 2>(psi_key) {}
119
120 /**
121 Check, whether the plugin specified by the plugin argument has been
122 already added into the array.
123
124 @param plugin Plugin to check.
125
126 @retval true Plugin has been already added.
127 @retval false There is no plugin in the array.
128 */
129 bool exists(plugin_ref plugin) {
131
132 for (i = begin(); i != end(); ++i)
133 if (plugin_equals(*i, plugin)) return true;
134
135 return false;
136 }
137};
138
139#endif // SQL_PLUGIN_REF_INCLUDED
Plugin array helper class.
Definition: sql_plugin_ref.h:110
Plugin_array(PSI_memory_key psi_key)
Class construction.
Definition: sql_plugin_ref.h:117
bool exists(plugin_ref plugin)
Check, whether the plugin specified by the plugin argument has been already added into the array.
Definition: sql_plugin_ref.h:129
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:71
iterator begin()
begin : Returns a pointer to the first element in the array.
Definition: prealloced_array.h:254
iterator end()
Definition: prealloced_array.h:255
A class representing one system variable - that is something that can be accessed as @global....
Definition: set_var.h:106
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
uint plugin_state(st_plugin_int **ref)
Definition: sql_plugin_ref.h:96
enum_plugin_load_option plugin_load_option(st_plugin_int **ref)
Definition: sql_plugin_ref.h:97
struct st_plugin_int ** plugin_ref
Definition: sql_plugin_ref.h:83
st_mysql_plugin * plugin_decl(st_plugin_int **ref)
Definition: sql_plugin_ref.h:85
T plugin_data(st_plugin_int **ref)
Definition: sql_plugin_ref.h:92
st_plugin_dl * plugin_dlib(st_plugin_int **ref)
Definition: sql_plugin_ref.h:88
LEX_CSTRING * plugin_name(st_plugin_int **ref)
Definition: sql_plugin_ref.h:95
enum_plugin_load_option
Definition: sql_plugin_ref.h:36
@ PLUGIN_OFF
Definition: sql_plugin_ref.h:37
@ PLUGIN_FORCE_PLUS_PERMANENT
Definition: sql_plugin_ref.h:40
@ PLUGIN_FORCE
Definition: sql_plugin_ref.h:39
@ PLUGIN_ON
Definition: sql_plugin_ref.h:38
bool plugin_equals(st_plugin_int **ref1, st_plugin_int **ref2)
Definition: sql_plugin_ref.h:100
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: mysql_lex_string.h:40
Definition: plugin.h:635
Definition: sql_plugin.h:85
Definition: sql_plugin_ref.h:45
uint state
Definition: sql_plugin_ref.h:49
MEM_ROOT mem_root
Definition: sql_plugin_ref.h:52
uint ref_count
Definition: sql_plugin_ref.h:50
void * data
Definition: sql_plugin_ref.h:51
sys_var * system_vars
Definition: sql_plugin_ref.h:53
enum_plugin_load_option load_option
Definition: sql_plugin_ref.h:54
st_mysql_plugin * plugin
Definition: sql_plugin_ref.h:47
st_plugin_dl * plugin_dl
Definition: sql_plugin_ref.h:48
LEX_CSTRING name
Definition: sql_plugin_ref.h:46