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-1335 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,const char *v); 32 extern bool throw_bounds_warning(THD *thd, const char *name, 33 bool fixed, bool is_unsigned, longlong v); 34 extern bool throw_bounds_warning(THD *thd, const char *name, bool fixed, 35 double v); 36 extern sys_var *intern_find_sys_var(const char *str, size_t length); 37 38 extern sys_var_chain all_sys_vars; 39 40 /** wrapper to hide a mutex and an rwlock under a common interface */ 41 class PolyLock 42 { 43 public: 44 virtual void rdlock()= 0; 45 virtual void wrlock()= 0; 46 virtual void unlock()= 0; ~PolyLock()47 virtual ~PolyLock() {} 48 }; 49 50 class PolyLock_mutex: public PolyLock 51 { 52 mysql_mutex_t *mutex; 53 public: PolyLock_mutex(mysql_mutex_t * arg)54 PolyLock_mutex(mysql_mutex_t *arg): mutex(arg) {} rdlock()55 void rdlock() { mysql_mutex_lock(mutex); } wrlock()56 void wrlock() { mysql_mutex_lock(mutex); } unlock()57 void unlock() { mysql_mutex_unlock(mutex); } 58 }; 59 60 class PolyLock_rwlock: public PolyLock 61 { 62 mysql_rwlock_t *rwlock; 63 public: PolyLock_rwlock(mysql_rwlock_t * arg)64 PolyLock_rwlock(mysql_rwlock_t *arg): rwlock(arg) {} rdlock()65 void rdlock() { mysql_rwlock_rdlock(rwlock); } wrlock()66 void wrlock() { mysql_rwlock_wrlock(rwlock); } unlock()67 void unlock() { mysql_rwlock_unlock(rwlock); } 68 }; 69 70 class AutoWLock 71 { 72 PolyLock *lock; 73 public: AutoWLock(PolyLock * l)74 AutoWLock(PolyLock *l) : lock(l) { if (lock) lock->wrlock(); } ~AutoWLock()75 ~AutoWLock() { if (lock) lock->unlock(); } 76 }; 77 78 class AutoRLock 79 { 80 PolyLock *lock; 81 public: AutoRLock(PolyLock * l)82 AutoRLock(PolyLock *l) : lock(l) { if (lock) lock->rdlock(); } ~AutoRLock()83 ~AutoRLock() { if (lock) lock->unlock(); } 84 }; 85 86 87 #endif /* SYS_VARS_SHARED_INCLUDED */ 88