@@ -3403,13 +3403,33 @@ void alloc_and_copy_thd_dynamic_variables(THD *thd) {
3403
3403
mysql_mutex_unlock (&LOCK_system_variables_hash);
3404
3404
}
3405
3405
3406
- static bool is_regular_call (THD *thd) {
3406
+ static bool is_regular_session_thdvar_call (THD *thd) {
3407
3407
if (thd == nullptr ) {
3408
- return true ;
3408
+ /*
3409
+ This is a call to THDVAR(nullptr, var).
3410
+ The call is to get a GLOBAL value, not per SESSION.
3411
+
3412
+ current_thd->m_inside_system_variable_global_update
3413
+ might be true or false,
3414
+ but this is not relevant since no SESSION variable is accessed.
3415
+ */
3416
+ return false ;
3409
3417
}
3410
3418
if (!thd->m_inside_system_variable_global_update ) {
3419
+ /*
3420
+ This is a call to THDVAR(thd, var).
3421
+ The call is made from regular code,
3422
+ as in, not nested within a system variable update.
3423
+ */
3411
3424
return true ;
3412
3425
}
3426
+ /*
3427
+ This is a call to THDVAR(thd, var_x).
3428
+ The code is nested, made from within another system variable
3429
+ update function, in SET GLOBAL var_y = ...
3430
+
3431
+ The mutex LOCK_global_system_variables is already held.
3432
+ */
3413
3433
return false ;
3414
3434
}
3415
3435
@@ -3423,85 +3443,50 @@ static bool is_regular_call(THD *thd) {
3423
3443
3424
3444
static bool *mysql_sys_var_bool (THD *thd, int offset) {
3425
3445
bool *result;
3426
- if (is_regular_call (thd)) {
3427
- mysql_mutex_lock (&LOCK_global_system_variables);
3428
- result = (bool *)intern_sys_var_ptr (thd, offset);
3429
- mysql_mutex_unlock (&LOCK_global_system_variables);
3430
- } else {
3431
- result = (bool *)intern_sys_var_ptr (thd, offset);
3432
- }
3446
+ bool need_lock = is_regular_session_thdvar_call (thd);
3447
+ result = (bool *)intern_sys_var_ptr (thd, offset, need_lock);
3433
3448
return result;
3434
3449
}
3435
3450
3436
3451
static int *mysql_sys_var_int (THD *thd, int offset) {
3437
3452
int *result;
3438
- if (is_regular_call (thd)) {
3439
- mysql_mutex_lock (&LOCK_global_system_variables);
3440
- result = (int *)intern_sys_var_ptr (thd, offset);
3441
- mysql_mutex_unlock (&LOCK_global_system_variables);
3442
- } else {
3443
- result = (int *)intern_sys_var_ptr (thd, offset);
3444
- }
3453
+ bool need_lock = is_regular_session_thdvar_call (thd);
3454
+ result = (int *)intern_sys_var_ptr (thd, offset, need_lock);
3445
3455
return result;
3446
3456
}
3447
3457
3448
3458
static unsigned int *mysql_sys_var_uint (THD *thd, int offset) {
3449
3459
unsigned int *result;
3450
- if (is_regular_call (thd)) {
3451
- mysql_mutex_lock (&LOCK_global_system_variables);
3452
- result = (unsigned int *)intern_sys_var_ptr (thd, offset);
3453
- mysql_mutex_unlock (&LOCK_global_system_variables);
3454
- } else {
3455
- result = (unsigned int *)intern_sys_var_ptr (thd, offset);
3456
- }
3460
+ bool need_lock = is_regular_session_thdvar_call (thd);
3461
+ result = (unsigned int *)intern_sys_var_ptr (thd, offset, need_lock);
3457
3462
return result;
3458
3463
}
3459
3464
3460
3465
static unsigned long *mysql_sys_var_ulong (THD *thd, int offset) {
3461
3466
unsigned long *result;
3462
- if (is_regular_call (thd)) {
3463
- mysql_mutex_lock (&LOCK_global_system_variables);
3464
- result = (unsigned long *)intern_sys_var_ptr (thd, offset);
3465
- mysql_mutex_unlock (&LOCK_global_system_variables);
3466
- } else {
3467
- result = (unsigned long *)intern_sys_var_ptr (thd, offset);
3468
- }
3467
+ bool need_lock = is_regular_session_thdvar_call (thd);
3468
+ result = (unsigned long *)intern_sys_var_ptr (thd, offset, need_lock);
3469
3469
return result;
3470
3470
}
3471
3471
3472
3472
static unsigned long long *mysql_sys_var_ulonglong (THD *thd, int offset) {
3473
3473
unsigned long long *result;
3474
- if (is_regular_call (thd)) {
3475
- mysql_mutex_lock (&LOCK_global_system_variables);
3476
- result = (unsigned long long *)intern_sys_var_ptr (thd, offset);
3477
- mysql_mutex_unlock (&LOCK_global_system_variables);
3478
- } else {
3479
- result = (unsigned long long *)intern_sys_var_ptr (thd, offset);
3480
- }
3474
+ bool need_lock = is_regular_session_thdvar_call (thd);
3475
+ result = (unsigned long long *)intern_sys_var_ptr (thd, offset, need_lock);
3481
3476
return result;
3482
3477
}
3483
3478
3484
3479
static char **mysql_sys_var_str (THD *thd, int offset) {
3485
3480
char **result;
3486
- if (is_regular_call (thd)) {
3487
- mysql_mutex_lock (&LOCK_global_system_variables);
3488
- result = (char **)intern_sys_var_ptr (thd, offset);
3489
- mysql_mutex_unlock (&LOCK_global_system_variables);
3490
- } else {
3491
- result = (char **)intern_sys_var_ptr (thd, offset);
3492
- }
3481
+ bool need_lock = is_regular_session_thdvar_call (thd);
3482
+ result = (char **)intern_sys_var_ptr (thd, offset, need_lock);
3493
3483
return result;
3494
3484
}
3495
3485
3496
3486
static double *mysql_sys_var_double (THD *thd, int offset) {
3497
3487
double *result;
3498
- if (is_regular_call (thd)) {
3499
- mysql_mutex_lock (&LOCK_global_system_variables);
3500
- result = (double *)intern_sys_var_ptr (thd, offset);
3501
- mysql_mutex_unlock (&LOCK_global_system_variables);
3502
- } else {
3503
- result = (double *)intern_sys_var_ptr (thd, offset);
3504
- }
3488
+ bool need_lock = is_regular_session_thdvar_call (thd);
3489
+ result = (double *)intern_sys_var_ptr (thd, offset, need_lock);
3505
3490
return result;
3506
3491
}
3507
3492
0 commit comments