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 Foundation,
24    51 Franklin Street, Suite 500, Boston, MA 02110-1335 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 "my_global.h"
36 
37 class THD;
38 class sys_var;
39 
40 extern bool throw_bounds_warning(THD *thd, const char *name,
41                                  bool fixed, bool is_unsigned, longlong v);
42 extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed,
43                                  double v);
44 extern sys_var *intern_find_sys_var(const char *str, size_t length);
45 
46 /** wrapper to hide a mutex and an rwlock under a common interface */
47 class PolyLock
48 {
49 public:
50   virtual void rdlock()= 0;
51   virtual void wrlock()= 0;
52   virtual void unlock()= 0;
~PolyLock()53   virtual ~PolyLock() {}
54 };
55 
56 class PolyLock_mutex: public PolyLock
57 {
58   mysql_mutex_t *mutex;
59 public:
PolyLock_mutex(mysql_mutex_t * arg)60   PolyLock_mutex(mysql_mutex_t *arg): mutex(arg) {}
rdlock()61   void rdlock() { mysql_mutex_lock(mutex); }
wrlock()62   void wrlock() { mysql_mutex_lock(mutex); }
unlock()63   void unlock() { mysql_mutex_unlock(mutex); }
64 };
65 
66 class PolyLock_rwlock: public PolyLock
67 {
68   mysql_rwlock_t *rwlock;
69 public:
PolyLock_rwlock(mysql_rwlock_t * arg)70   PolyLock_rwlock(mysql_rwlock_t *arg): rwlock(arg) {}
rdlock()71   void rdlock() { mysql_rwlock_rdlock(rwlock); }
wrlock()72   void wrlock() { mysql_rwlock_wrlock(rwlock); }
unlock()73   void unlock() { mysql_rwlock_unlock(rwlock); }
74 };
75 
76 class PolyLock_lock_log: public PolyLock
77 {
78 public:
79   void rdlock();
80   void wrlock();
81   void unlock();
82 };
83 
84 class AutoWLock
85 {
86   PolyLock *lock;
87 public:
AutoWLock(PolyLock * l)88   AutoWLock(PolyLock *l) : lock(l) { if (lock) lock->wrlock(); }
~AutoWLock()89   ~AutoWLock() { if (lock) lock->unlock(); }
90 };
91 
92 class AutoRLock
93 {
94   PolyLock *lock;
95 public:
AutoRLock(PolyLock * l)96   AutoRLock(PolyLock *l) : lock(l) { if (lock) lock->rdlock(); }
~AutoRLock()97   ~AutoRLock() { if (lock) lock->unlock(); }
98 };
99 
100 
101 #endif /* SYS_VARS_SHARED_INCLUDED */
102