Commit b969a690 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: simplify sys_var::val* methods, introduce val_str_nolock()

parent a4e7d339
...@@ -263,9 +263,7 @@ bool sys_var::set_default(THD *thd, set_var* var) ...@@ -263,9 +263,7 @@ bool sys_var::set_default(THD *thd, set_var* var)
#define do_num_val(T,CMD) \ #define do_num_val(T,CMD) \
do { \ do { \
mysql_mutex_lock(&LOCK_global_system_variables); \ T val= *(T*) value; \
T val= *(T*) value_ptr(thd, type, base); \
mysql_mutex_unlock(&LOCK_global_system_variables); \
CMD; \ CMD; \
} while (0) } while (0)
...@@ -285,25 +283,25 @@ do { \ ...@@ -285,25 +283,25 @@ do { \
#define case_get_string_as_lex_string \ #define case_get_string_as_lex_string \
case SHOW_CHAR: \ case SHOW_CHAR: \
mysql_mutex_lock(&LOCK_global_system_variables); \ sval.str= (char*) value; \
sval.str= (char*) value_ptr(thd, type, base); \
sval.length= sval.str ? strlen(sval.str) : 0; \ sval.length= sval.str ? strlen(sval.str) : 0; \
break; \ break; \
case SHOW_CHAR_PTR: \ case SHOW_CHAR_PTR: \
mysql_mutex_lock(&LOCK_global_system_variables); \ sval.str= *(char**) value; \
sval.str= *(char**) value_ptr(thd, type, base); \
sval.length= sval.str ? strlen(sval.str) : 0; \ sval.length= sval.str ? strlen(sval.str) : 0; \
break; \ break; \
case SHOW_LEX_STRING: \ case SHOW_LEX_STRING: \
mysql_mutex_lock(&LOCK_global_system_variables); \ sval= *(LEX_STRING *) value; \
sval= *(LEX_STRING *) value_ptr(thd, type, base); \
break break
longlong sys_var::val_int(bool *is_null, 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; LEX_STRING sval;
AutoWLock lock(&PLock_global_system_variables);
const uchar *value= value_ptr(thd, type, base);
*is_null= false; *is_null= false;
switch (show_type()) switch (show_type())
{ {
case_get_string_as_lex_string; case_get_string_as_lex_string;
...@@ -318,13 +316,11 @@ longlong sys_var::val_int(bool *is_null, ...@@ -318,13 +316,11 @@ longlong sys_var::val_int(bool *is_null,
if (!(*is_null= !sval.str)) if (!(*is_null= !sval.str))
ret= longlong_from_string_with_check(system_charset_info, ret= longlong_from_string_with_check(system_charset_info,
sval.str, sval.str + sval.length); sval.str, sval.str + sval.length);
mysql_mutex_unlock(&LOCK_global_system_variables);
return ret; return ret;
} }
String *sys_var::val_str(String *str, String *sys_var::val_str_nolock(String *str, THD *thd, const uchar *value)
THD *thd, enum_var_type type, LEX_STRING *base)
{ {
LEX_STRING sval; LEX_STRING sval;
switch (show_type()) switch (show_type())
...@@ -339,16 +335,27 @@ String *sys_var::val_str(String *str, ...@@ -339,16 +335,27 @@ String *sys_var::val_str(String *str,
if (!sval.str || str->copy(sval.str, sval.length, system_charset_info)) if (!sval.str || str->copy(sval.str, sval.length, system_charset_info))
str= NULL; str= NULL;
mysql_mutex_unlock(&LOCK_global_system_variables);
return str; 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, 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; LEX_STRING sval;
AutoWLock lock(&PLock_global_system_variables);
const uchar *value= value_ptr(thd, type, base);
*is_null= false; *is_null= false;
switch (show_type()) switch (show_type())
{ {
case_get_string_as_lex_string; case_get_string_as_lex_string;
......
...@@ -117,9 +117,10 @@ class sys_var ...@@ -117,9 +117,10 @@ class sys_var
bool set_default(THD *thd, set_var *var); bool set_default(THD *thd, set_var *var);
bool update(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_nolock(String *str, THD *thd, const uchar *value);
String *val_str(String *str, THD *thd, enum_var_type type, LEX_STRING *base); longlong val_int(bool *is_null, THD *thd, enum_var_type type, const LEX_STRING *base);
double val_real(bool *is_null, THD *thd, enum_var_type type, 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; } SHOW_TYPE show_type() { return show_val_type; }
int scope() const { return flags & SCOPE_MASK; } int scope() const { return flags & SCOPE_MASK; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment