MySQL 8.3.0
Source Code Documentation
sql_plugin_ref.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2023, 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#ifndef SQL_PLUGIN_REF_INCLUDED
24#define SQL_PLUGIN_REF_INCLUDED
25
26#include "lex_string.h"
27#include "my_alloc.h"
29#include "prealloced_array.h"
30
31class sys_var;
32struct st_mysql_plugin;
33struct st_plugin_dl;
34
40};
41
42/* A handle of a plugin */
43
45 LEX_CSTRING name{nullptr, 0};
48 uint state{0};
49 uint ref_count{0}; /* number of threads using the plugin */
50 void *data{nullptr}; /* plugin type specific, e.g. handlerton */
51 MEM_ROOT mem_root; /* memory for dynamic plugin structures */
52 sys_var *system_vars{nullptr}; /* server variables for this plugin */
54 PLUGIN_OFF}; /* OFF, ON, FORCE, F+PERMANENT */
55};
56
57/*
58 See intern_plugin_lock() for the explanation for the
59 conditionally defined plugin_ref type
60*/
61
62#ifdef NDEBUG
63typedef struct st_plugin_int *plugin_ref;
64
65inline st_mysql_plugin *plugin_decl(st_plugin_int *ref) { return ref->plugin; }
66inline st_plugin_dl *plugin_dlib(st_plugin_int *ref) { return ref->plugin_dl; }
67template <typename T>
68inline T plugin_data(st_plugin_int *ref) {
69 return static_cast<T>(ref->data);
70}
71inline LEX_CSTRING *plugin_name(st_plugin_int *ref) { return &(ref->name); }
72inline uint plugin_state(st_plugin_int *ref) { return ref->state; }
74 return ref->load_option;
75}
76inline bool plugin_equals(st_plugin_int *ref1, st_plugin_int *ref2) {
77 return ref1 == ref2;
78}
79
80#else
81
82typedef struct st_plugin_int **plugin_ref;
83
85 return ref[0]->plugin;
86}
88 return ref[0]->plugin_dl;
89}
90template <typename T>
92 return static_cast<T>(ref[0]->data);
93}
94inline LEX_CSTRING *plugin_name(st_plugin_int **ref) { return &(ref[0]->name); }
95inline uint plugin_state(st_plugin_int **ref) { return ref[0]->state; }
97 return ref[0]->load_option;
98}
99inline bool plugin_equals(st_plugin_int **ref1, st_plugin_int **ref2) {
100 return ref1 && ref2 && (ref1[0] == ref2[0]);
101}
102#endif
103
104/**
105 @class Plugin_array
106
107 @brief Plugin array helper class.
108*/
109class Plugin_array : public Prealloced_array<plugin_ref, 2> {
110 public:
111 /**
112 Class construction.
113
114 @param psi_key PSI key.
115 */
116 explicit Plugin_array(PSI_memory_key psi_key)
117 : Prealloced_array<plugin_ref, 2>(psi_key) {}
118
119 /**
120 Check, whether the plugin specified by the plugin argument has been
121 already added into the array.
122
123 @param plugin Plugin to check.
124
125 @retval true Plugin has been already added.
126 @retval false There is no plugin in the array.
127 */
128 bool exists(plugin_ref plugin) {
130
131 for (i = begin(); i != end(); ++i)
132 if (plugin_equals(*i, plugin)) return true;
133
134 return false;
135 }
136};
137
138#endif // SQL_PLUGIN_REF_INCLUDED
Plugin array helper class.
Definition: sql_plugin_ref.h:109
Plugin_array(PSI_memory_key psi_key)
Class construction.
Definition: sql_plugin_ref.h:116
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:128
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:70
iterator begin()
begin : Returns a pointer to the first element in the array.
Definition: prealloced_array.h:253
iterator end()
Definition: prealloced_array.h:254
A class representing one system variable - that is something that can be accessed as @global....
Definition: set_var.h:105
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:48
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:358
uint plugin_state(st_plugin_int **ref)
Definition: sql_plugin_ref.h:95
enum_plugin_load_option plugin_load_option(st_plugin_int **ref)
Definition: sql_plugin_ref.h:96
struct st_plugin_int ** plugin_ref
Definition: sql_plugin_ref.h:82
st_mysql_plugin * plugin_decl(st_plugin_int **ref)
Definition: sql_plugin_ref.h:84
T plugin_data(st_plugin_int **ref)
Definition: sql_plugin_ref.h:91
st_plugin_dl * plugin_dlib(st_plugin_int **ref)
Definition: sql_plugin_ref.h:87
LEX_CSTRING * plugin_name(st_plugin_int **ref)
Definition: sql_plugin_ref.h:94
enum_plugin_load_option
Definition: sql_plugin_ref.h:35
@ PLUGIN_OFF
Definition: sql_plugin_ref.h:36
@ PLUGIN_FORCE_PLUS_PERMANENT
Definition: sql_plugin_ref.h:39
@ PLUGIN_FORCE
Definition: sql_plugin_ref.h:38
@ PLUGIN_ON
Definition: sql_plugin_ref.h:37
bool plugin_equals(st_plugin_int **ref1, st_plugin_int **ref2)
Definition: sql_plugin_ref.h:99
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: mysql_lex_string.h:39
Definition: plugin.h:634
Definition: sql_plugin.h:84
Definition: sql_plugin_ref.h:44
uint state
Definition: sql_plugin_ref.h:48
MEM_ROOT mem_root
Definition: sql_plugin_ref.h:51
uint ref_count
Definition: sql_plugin_ref.h:49
void * data
Definition: sql_plugin_ref.h:50
sys_var * system_vars
Definition: sql_plugin_ref.h:52
enum_plugin_load_option load_option
Definition: sql_plugin_ref.h:53
st_mysql_plugin * plugin
Definition: sql_plugin_ref.h:46
st_plugin_dl * plugin_dl
Definition: sql_plugin_ref.h:47
LEX_CSTRING name
Definition: sql_plugin_ref.h:45