summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2014-08-31 13:39:05 +0200
committerSergei Golubchik <serg@mariadb.org>2014-10-10 22:27:42 +0200
commitb969a690217f2364cd6c8b55315360223fe1f00b (patch)
treed8982b5fe32adfc0840b90942560bd9bd604e495
parenta4e7d339af0ea95b8b3c68e2b648294932e8550e (diff)
downloadmariadb-git-b969a690217f2364cd6c8b55315360223fe1f00b.tar.gz
cleanup: simplify sys_var::val* methods, introduce val_str_nolock()
-rw-r--r--sql/set_var.cc61
-rw-r--r--sql/set_var.h7
2 files changed, 38 insertions, 30 deletions
diff --git a/sql/set_var.cc b/sql/set_var.cc
index 1510f3a6c5e..bc9d7638ca6 100644
--- a/sql/set_var.cc
+++ b/sql/set_var.cc
@@ -261,12 +261,10 @@ bool sys_var::set_default(THD *thd, set_var* var)
}
-#define do_num_val(T,CMD) \
-do { \
- mysql_mutex_lock(&LOCK_global_system_variables); \
- T val= *(T*) value_ptr(thd, type, base); \
- mysql_mutex_unlock(&LOCK_global_system_variables); \
- CMD; \
+#define do_num_val(T,CMD) \
+do { \
+ T val= *(T*) value; \
+ CMD; \
} while (0)
#define case_for_integers(CMD) \
@@ -280,30 +278,30 @@ do { \
case SHOW_BOOL: do_num_val (bool,CMD); \
case SHOW_MY_BOOL: do_num_val (my_bool,CMD)
-#define case_for_double(CMD) \
+#define case_for_double(CMD) \
case SHOW_DOUBLE: do_num_val (double,CMD)
-#define case_get_string_as_lex_string \
- case SHOW_CHAR: \
- mysql_mutex_lock(&LOCK_global_system_variables); \
- sval.str= (char*) value_ptr(thd, type, base); \
- sval.length= sval.str ? strlen(sval.str) : 0; \
- break; \
- case SHOW_CHAR_PTR: \
- mysql_mutex_lock(&LOCK_global_system_variables); \
- sval.str= *(char**) value_ptr(thd, type, base); \
- sval.length= sval.str ? strlen(sval.str) : 0; \
- break; \
- case SHOW_LEX_STRING: \
- mysql_mutex_lock(&LOCK_global_system_variables); \
- sval= *(LEX_STRING *) value_ptr(thd, type, base); \
+#define case_get_string_as_lex_string \
+ case SHOW_CHAR: \
+ sval.str= (char*) value; \
+ sval.length= sval.str ? strlen(sval.str) : 0; \
+ break; \
+ case SHOW_CHAR_PTR: \
+ sval.str= *(char**) value; \
+ sval.length= sval.str ? strlen(sval.str) : 0; \
+ break; \
+ case SHOW_LEX_STRING: \
+ sval= *(LEX_STRING *) value; \
break
longlong sys_var::val_int(bool *is_null,
- THD *thd, enum_var_type type, LEX_STRING *base)
+ THD *thd, enum_var_type type, const LEX_STRING *base)
{
LEX_STRING sval;
+ AutoWLock lock(&PLock_global_system_variables);
+ const uchar *value= value_ptr(thd, type, base);
*is_null= false;
+
switch (show_type())
{
case_get_string_as_lex_string;
@@ -318,13 +316,11 @@ longlong sys_var::val_int(bool *is_null,
if (!(*is_null= !sval.str))
ret= longlong_from_string_with_check(system_charset_info,
sval.str, sval.str + sval.length);
- mysql_mutex_unlock(&LOCK_global_system_variables);
return ret;
}
-String *sys_var::val_str(String *str,
- THD *thd, enum_var_type type, LEX_STRING *base)
+String *sys_var::val_str_nolock(String *str, THD *thd, const uchar *value)
{
LEX_STRING sval;
switch (show_type())
@@ -339,16 +335,27 @@ String *sys_var::val_str(String *str,
if (!sval.str || str->copy(sval.str, sval.length, system_charset_info))
str= NULL;
- mysql_mutex_unlock(&LOCK_global_system_variables);
return str;
}
+String *sys_var::val_str(String *str,
+ THD *thd, enum_var_type type, const LEX_STRING *base)
+{
+ AutoWLock lock(&PLock_global_system_variables);
+ const uchar *value= value_ptr(thd, type, base);
+ return val_str_nolock(str, thd, value);
+}
+
+
double sys_var::val_real(bool *is_null,
- THD *thd, enum_var_type type, LEX_STRING *base)
+ THD *thd, enum_var_type type, const LEX_STRING *base)
{
LEX_STRING sval;
+ AutoWLock lock(&PLock_global_system_variables);
+ const uchar *value= value_ptr(thd, type, base);
*is_null= false;
+
switch (show_type())
{
case_get_string_as_lex_string;
diff --git a/sql/set_var.h b/sql/set_var.h
index d6398006ca6..b495c17867d 100644
--- a/sql/set_var.h
+++ b/sql/set_var.h
@@ -117,9 +117,10 @@ public:
bool set_default(THD *thd, set_var *var);
bool update(THD *thd, set_var *var);
- longlong val_int(bool *is_null, THD *thd, enum_var_type type, LEX_STRING *base);
- String *val_str(String *str, THD *thd, enum_var_type type, LEX_STRING *base);
- double val_real(bool *is_null, THD *thd, enum_var_type type, LEX_STRING *base);
+ String *val_str_nolock(String *str, THD *thd, const uchar *value);
+ longlong val_int(bool *is_null, THD *thd, enum_var_type type, const LEX_STRING *base);
+ String *val_str(String *str, THD *thd, enum_var_type type, const LEX_STRING *base);
+ double val_real(bool *is_null, THD *thd, enum_var_type type, const LEX_STRING *base);
SHOW_TYPE show_type() { return show_val_type; }
int scope() const { return flags & SCOPE_MASK; }