MySQL  8.0.17
Source Code Documentation
sql_plugin_ref.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
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"
28 #include "mysql/mysql_lex_string.h"
29 #include "prealloced_array.h"
30 
31 class sys_var;
32 struct st_mysql_plugin;
33 struct st_plugin_dl;
34 
40 };
41 
42 /* A handle of a plugin */
43 
44 struct st_plugin_int {
45  LEX_STRING 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 DBUG_OFF
63 typedef struct st_plugin_int *plugin_ref;
64 
65 inline st_mysql_plugin *plugin_decl(st_plugin_int *ref) { return ref->plugin; }
66 inline st_plugin_dl *plugin_dlib(st_plugin_int *ref) { return ref->plugin_dl; }
67 template <typename T>
68 inline T plugin_data(st_plugin_int *ref) {
69  return static_cast<T>(ref->data);
70 }
71 inline LEX_STRING *plugin_name(st_plugin_int *ref) { return &(ref->name); }
72 inline uint plugin_state(st_plugin_int *ref) { return ref->state; }
74  return ref->load_option;
75 }
76 inline bool plugin_equals(st_plugin_int *ref1, st_plugin_int *ref2) {
77  return ref1 == ref2;
78 }
79 
80 #else
81 
82 typedef struct st_plugin_int **plugin_ref;
83 
85  return ref[0]->plugin;
86 }
88  return ref[0]->plugin_dl;
89 }
90 template <typename T>
91 inline T plugin_data(st_plugin_int **ref) {
92  return static_cast<T>(ref[0]->data);
93 }
94 inline LEX_STRING *plugin_name(st_plugin_int **ref) { return &(ref[0]->name); }
95 inline uint plugin_state(st_plugin_int **ref) { return ref[0]->state; }
97  return ref[0]->load_option;
98 }
99 inline 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 */
109 class 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  */
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
Definition: sql_plugin_ref.h:44
LEX_STRING * plugin_name(st_plugin_int **ref)
Definition: sql_plugin_ref.h:94
struct st_plugin_int ** plugin_ref
Definition: sql_plugin_ref.h:82
Definition: mysql_lex_string.h:34
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
uint ref_count
Definition: sql_plugin_ref.h:49
Plugin array helper class.
Definition: sql_plugin_ref.h:109
uint plugin_state(st_plugin_int **ref)
Definition: sql_plugin_ref.h:95
Definition: plugin.h:636
st_mysql_plugin * plugin
Definition: sql_plugin_ref.h:46
void * data
Definition: sql_plugin_ref.h:50
Definition: sql_plugin_ref.h:36
st_plugin_dl * plugin_dl
Definition: sql_plugin_ref.h:47
Definition: sql_plugin_ref.h:39
static struct st_mysql_daemon plugin
Definition: test_services_host_application_signal.cc:130
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:46
Definition: sql_plugin_ref.h:38
sys_var * system_vars
Definition: sql_plugin_ref.h:52
iterator begin()
begin : Returns a pointer to the first element in the array.
Definition: prealloced_array.h:210
A typesafe replacement for DYNAMIC_ARRAY.
Definition: prealloced_array.h:66
A class representing one system variable - that is something that can be accessed as @global...
Definition: set_var.h:102
bool plugin_equals(st_plugin_int **ref1, st_plugin_int **ref2)
Definition: sql_plugin_ref.h:99
uint state
Definition: sql_plugin_ref.h:48
MEM_ROOT mem_root
Definition: sql_plugin_ref.h:51
Definition: sql_plugin.h:82
T plugin_data(st_plugin_int **ref)
Definition: sql_plugin_ref.h:91
unsigned int uint
Definition: uca-dump.cc:29
enum_plugin_load_option load_option
Definition: sql_plugin_ref.h:53
st_plugin_dl * plugin_dlib(st_plugin_int **ref)
Definition: sql_plugin_ref.h:87
iterator end()
Definition: prealloced_array.h:211
LEX_STRING name
Definition: sql_plugin_ref.h:45
enum_plugin_load_option plugin_load_option(st_plugin_int **ref)
Definition: sql_plugin_ref.h:96
Definition: sql_plugin_ref.h:37
st_mysql_plugin * plugin_decl(st_plugin_int **ref)
Definition: sql_plugin_ref.h:84
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
enum_plugin_load_option
Definition: sql_plugin_ref.h:35
Plugin_array(PSI_memory_key psi_key)
Class construction.
Definition: sql_plugin_ref.h:116
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...