MySQL  8.0.27
Source Code Documentation
sys_vars_shared.h
Go to the documentation of this file.
1 #ifndef SYS_VARS_SHARED_INCLUDED
2 #define SYS_VARS_SHARED_INCLUDED
3 
4 /* Copyright (c) 2002, 2021, Oracle and/or its affiliates.
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License, version 2.0,
8  as published by the Free Software Foundation.
9 
10  This program is also distributed with certain software (including
11  but not limited to OpenSSL) that is licensed under separate terms,
12  as designated in a particular file or component or in included license
13  documentation. The authors of MySQL hereby grant you an additional
14  permission to link the program and your derivative works with the
15  separately licensed software that they have included with MySQL.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License, version 2.0, for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25 
26 /**
27  @file
28  "protected" interface to sys_var - server configuration variables.
29 
30  This header is included by files implementing support and utility
31  functions of sys_var's (set_var.cc) and files implementing
32  classes in the sys_var hierarchy (sql_plugin.cc)
33 */
34 
35 #include "mysql/psi/mysql_mutex.h"
36 #include "mysql/psi/mysql_thread.h" // mysql_mutex_t
37 #include "sql/sql_table.h"
38 
39 class THD;
40 class sys_var;
41 
42 extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed,
43  bool is_unsigned, longlong v);
44 extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed,
45  double v);
46 extern sys_var *intern_find_sys_var(const char *str, size_t length);
47 
48 /** wrapper to hide a mutex and an rwlock under a common interface */
49 class PolyLock {
50  public:
51  virtual void rdlock() = 0;
52  virtual void wrlock() = 0;
53  virtual void unlock() = 0;
54  virtual ~PolyLock() = default;
55 };
56 
57 class PolyLock_mutex : public PolyLock {
59 
60  public:
62  void rdlock() override { mysql_mutex_lock(mutex); }
63  void wrlock() override { mysql_mutex_lock(mutex); }
64  void unlock() override { mysql_mutex_unlock(mutex); }
65 };
66 
67 class PolyLock_rwlock : public PolyLock {
69 
70  public:
72  void rdlock() override { mysql_rwlock_rdlock(rwlock); }
73  void wrlock() override { mysql_rwlock_wrlock(rwlock); }
74  void unlock() override { mysql_rwlock_unlock(rwlock); }
75 };
76 
77 class PolyLock_lock_log : public PolyLock {
78  public:
79  void rdlock() override;
80  void wrlock() override;
81  void unlock() override;
82 };
83 
84 class AutoWLock {
86 
87  public:
88  AutoWLock(PolyLock *l) : lock(l) {
89  if (lock) lock->wrlock();
90  }
92  if (lock) lock->unlock();
93  }
94 };
95 
96 class AutoRLock {
98 
99  public:
101  if (lock) lock->rdlock();
102  }
104  if (lock) lock->unlock();
105  }
106 };
107 
108 #endif /* SYS_VARS_SHARED_INCLUDED */
Definition: sys_vars_shared.h:96
~AutoRLock()
Definition: sys_vars_shared.h:103
PolyLock * lock
Definition: sys_vars_shared.h:97
AutoRLock(PolyLock *l)
Definition: sys_vars_shared.h:100
Definition: sys_vars_shared.h:84
~AutoWLock()
Definition: sys_vars_shared.h:91
AutoWLock(PolyLock *l)
Definition: sys_vars_shared.h:88
PolyLock * lock
Definition: sys_vars_shared.h:85
Definition: sys_vars_shared.h:77
void wrlock() override
void unlock() override
void rdlock() override
Definition: sys_vars_shared.h:57
PolyLock_mutex(mysql_mutex_t *arg)
Definition: sys_vars_shared.h:61
mysql_mutex_t * mutex
Definition: sys_vars_shared.h:58
void wrlock() override
Definition: sys_vars_shared.h:63
void unlock() override
Definition: sys_vars_shared.h:64
void rdlock() override
Definition: sys_vars_shared.h:62
Definition: sys_vars_shared.h:67
void rdlock() override
Definition: sys_vars_shared.h:72
mysql_rwlock_t * rwlock
Definition: sys_vars_shared.h:68
PolyLock_rwlock(mysql_rwlock_t *arg)
Definition: sys_vars_shared.h:71
void wrlock() override
Definition: sys_vars_shared.h:73
void unlock() override
Definition: sys_vars_shared.h:74
wrapper to hide a mutex and an rwlock under a common interface
Definition: sys_vars_shared.h:49
virtual void wrlock()=0
virtual ~PolyLock()=default
virtual void rdlock()=0
virtual void unlock()=0
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
A class representing one system variable - that is something that can be accessed as @global....
Definition: set_var.h:102
#define mysql_mutex_lock(M)
Definition: mysql_mutex.h:49
#define mysql_mutex_unlock(M)
Definition: mysql_mutex.h:56
#define mysql_rwlock_rdlock(T)
Definition: mysql_rwlock.h:60
#define mysql_rwlock_unlock(T)
Definition: mysql_rwlock.h:90
#define mysql_rwlock_wrlock(T)
Definition: mysql_rwlock.h:70
Instrumentation helpers for mysys threads.
long long int longlong
Definition: my_inttypes.h:54
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1056
constexpr value_type is_unsigned
Definition: classic_protocol_constants.h:268
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:78
Instrumentation helpers for mutexes.
case opt name
Definition: sslopt-case.h:32
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
An instrumented rwlock structure.
Definition: mysql_rwlock_bits.h:50
bool throw_bounds_warning(THD *thd, const char *name, bool fixed, bool is_unsigned, longlong v)
Throw warning (error in STRICT mode) if value for variable needed bounding.
Definition: set_var.cc:516
sys_var * intern_find_sys_var(const char *str, size_t length)
Find a user set-table variable.
Definition: set_var.cc:793