diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2018-06-05 11:50:15 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2018-06-05 11:58:10 +0400 |
commit | c5b3a2754f3db6fd0b3054a2e83420378c8d2a0c (patch) | |
tree | e6b363a4812c4870f5ac5c0c967da69e2bc7b276 | |
parent | 8bea886332cdb27121f2df89a2b8d342f3e6aae0 (diff) | |
download | mariadb-git-c5b3a2754f3db6fd0b3054a2e83420378c8d2a0c.tar.gz |
MDEV-16371 - Fix for memory write order inversion
Removed incorrect usage of my_thread_var->mutex. Now it is used
exclusively for interruptable waits.
-rw-r--r-- | mysys/thr_timer.c | 13 | ||||
-rw-r--r-- | plugin/handler_socket/handlersocket/database.cpp | 4 |
2 files changed, 8 insertions, 9 deletions
diff --git a/mysys/thr_timer.c b/mysys/thr_timer.c index b8726617f44..530ac15a4f7 100644 --- a/mysys/thr_timer.c +++ b/mysys/thr_timer.c @@ -313,6 +313,7 @@ static void *timer_handler(void *arg __attribute__((unused))) static mysql_cond_t COND_thread_count; static mysql_mutex_t LOCK_thread_count; +static mysql_mutex_t test_mutex; static uint thread_count, benchmark_runs, test_to_run= 1; static void send_signal(void *arg) @@ -321,9 +322,9 @@ static void send_signal(void *arg) #if defined(MAIN) printf("sending signal\n"); fflush(stdout); #endif - mysql_mutex_lock(¤t_my_thread_var->mutex); + mysql_mutex_lock(&test_mutex); mysql_cond_signal(¤t_my_thread_var->suspend); - mysql_mutex_unlock(¤t_my_thread_var->mutex); + mysql_mutex_unlock(&test_mutex); } @@ -343,7 +344,7 @@ static void run_thread_test(int param) wait_time=param ? 11-i : i; start_time= my_hrtime(); - mysql_mutex_lock(¤t_my_thread_var->mutex); + mysql_mutex_lock(&test_mutex); if (thr_timer_settime(&timer_data, wait_time * 1000000)) { printf("Thread: %s timers aborted\n",my_thread_name()); @@ -360,7 +361,7 @@ static void run_thread_test(int param) { printf("Thread: %s Waiting %d sec\n",my_thread_name(),wait_time); mysql_cond_wait(¤t_my_thread_var->suspend, - ¤t_my_thread_var->mutex); + &test_mutex); } if (!timer_data.expired) @@ -370,7 +371,7 @@ static void run_thread_test(int param) break; } } - mysql_mutex_unlock(¤t_my_thread_var->mutex); + mysql_mutex_unlock(&test_mutex); printf("Thread: %s Slept for %g (%d) sec\n",my_thread_name(), (int) (my_hrtime().val-start_time.val)/1000000.0, wait_time); fflush(stdout); @@ -502,6 +503,7 @@ static void run_test() } mysql_mutex_init(0, &LOCK_thread_count, MY_MUTEX_INIT_FAST); + mysql_mutex_init(0, &test_mutex, MY_MUTEX_INIT_FAST); mysql_cond_init(0, &COND_thread_count, NULL); thr_setconcurrency(3); @@ -533,6 +535,7 @@ static void run_test() mysql_mutex_unlock(&LOCK_thread_count); DBUG_ASSERT(timer_queue.elements == 1); end_thr_timer(); + mysql_mutex_destroy(&test_mutex); printf("Test succeeded\n"); DBUG_VOID_RETURN; } diff --git a/plugin/handler_socket/handlersocket/database.cpp b/plugin/handler_socket/handlersocket/database.cpp index a76428b29d3..df36085bd87 100644 --- a/plugin/handler_socket/handlersocket/database.cpp +++ b/plugin/handler_socket/handlersocket/database.cpp @@ -244,9 +244,7 @@ wait_server_to_start(THD *thd, volatile int& shutdown_flag) pthread_cond_timedwait(&COND_server_started, &LOCK_server_started, &abstime); pthread_mutex_unlock(&LOCK_server_started); - pthread_mutex_lock(&thd->mysys_var->mutex); killed_state st = thd->killed; - pthread_mutex_unlock(&thd->mysys_var->mutex); DBG_SHUT(fprintf(stderr, "HNDSOCK wsts kst %d\n", (int)st)); pthread_mutex_lock(&LOCK_server_started); if (st != NOT_KILLED) { @@ -352,9 +350,7 @@ dbcontext::term_thread() bool dbcontext::check_alive() { - pthread_mutex_lock(&thd->mysys_var->mutex); killed_state st = thd->killed; - pthread_mutex_unlock(&thd->mysys_var->mutex); DBG_SHUT(fprintf(stderr, "chk HNDSOCK kst %p %p %d %zu\n", thd, &thd->killed, (int)st, sizeof(*thd))); if (st != NOT_KILLED) { |