1 | #ifndef SYS_VARS_SHARED_INCLUDED |
2 | #define SYS_VARS_SHARED_INCLUDED |
3 | |
4 | /* Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
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 as published by |
8 | the Free Software Foundation; version 2 of the License. |
9 | |
10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
18 | |
19 | /** |
20 | @file |
21 | "protected" interface to sys_var - server configuration variables. |
22 | |
23 | This header is included by files implementing support and utility |
24 | functions of sys_var's (set_var.cc) and files implementing |
25 | classes in the sys_var hierarchy (sql_plugin.cc) |
26 | */ |
27 | |
28 | #include <sql_priv.h> |
29 | #include "set_var.h" |
30 | |
31 | extern bool throw_bounds_warning(THD *thd, const char *name, |
32 | bool fixed, bool is_unsigned, longlong v); |
33 | extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed, |
34 | double v); |
35 | extern sys_var *intern_find_sys_var(const char *str, size_t length); |
36 | |
37 | extern sys_var_chain all_sys_vars; |
38 | |
39 | /** wrapper to hide a mutex and an rwlock under a common interface */ |
40 | class PolyLock |
41 | { |
42 | public: |
43 | virtual void rdlock()= 0; |
44 | virtual void wrlock()= 0; |
45 | virtual void unlock()= 0; |
46 | virtual ~PolyLock() {} |
47 | }; |
48 | |
49 | class PolyLock_mutex: public PolyLock |
50 | { |
51 | mysql_mutex_t *mutex; |
52 | public: |
53 | PolyLock_mutex(mysql_mutex_t *arg): mutex(arg) {} |
54 | void rdlock() { mysql_mutex_lock(mutex); } |
55 | void wrlock() { mysql_mutex_lock(mutex); } |
56 | void unlock() { mysql_mutex_unlock(mutex); } |
57 | }; |
58 | |
59 | class PolyLock_rwlock: public PolyLock |
60 | { |
61 | mysql_rwlock_t *rwlock; |
62 | public: |
63 | PolyLock_rwlock(mysql_rwlock_t *arg): rwlock(arg) {} |
64 | void rdlock() { mysql_rwlock_rdlock(rwlock); } |
65 | void wrlock() { mysql_rwlock_wrlock(rwlock); } |
66 | void unlock() { mysql_rwlock_unlock(rwlock); } |
67 | }; |
68 | |
69 | class AutoWLock |
70 | { |
71 | PolyLock *lock; |
72 | public: |
73 | AutoWLock(PolyLock *l) : lock(l) { if (lock) lock->wrlock(); } |
74 | ~AutoWLock() { if (lock) lock->unlock(); } |
75 | }; |
76 | |
77 | class AutoRLock |
78 | { |
79 | PolyLock *lock; |
80 | public: |
81 | AutoRLock(PolyLock *l) : lock(l) { if (lock) lock->rdlock(); } |
82 | ~AutoRLock() { if (lock) lock->unlock(); } |
83 | }; |
84 | |
85 | |
86 | #endif /* SYS_VARS_SHARED_INCLUDED */ |
87 | |