Commit 86a2d707 authored by Sergei Golubchik's avatar Sergei Golubchik

safe_mutex deadlock detector post-merge fixes

parent 957b5590
......@@ -512,11 +512,13 @@ void safe_mutex_free_deadlock_data(safe_mutex_t *mp);
#define safe_mutex_assert_not_owner(mp) \
DBUG_ASSERT(! (mp)->count || \
! pthread_equal(pthread_self(), (mp)->thread))
#define safe_mutex_setflags(mp, F) do { (mp)->create_flags|= (F); } while (0)
#else
#define my_pthread_mutex_init(A,B,C,D) pthread_mutex_init((A),(B))
#define safe_mutex_assert_owner(mp) do {} while(0)
#define safe_mutex_assert_not_owner(mp) do {} while(0)
#define safe_mutex_free_deadlock_data(mp) do {} while(0)
#define safe_mutex_setflags(mp, F) do {} while (0)
#endif /* SAFE_MUTEX */
#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
......@@ -920,6 +922,16 @@ extern uint thd_lib_detected;
#define status_var_add(V,C) (V)+=(C)
#define status_var_sub(V,C) (V)-=(C)
#ifdef SAFE_MUTEX
#define mysql_mutex_record_order(A,B) \
do { \
mysql_mutex_lock(A); mysql_mutex_lock(B); \
mysql_mutex_unlock(B); mysql_mutex_unlock(A); \
} while(0)
#else
#define mysql_mutex_record_order(A,B) do { } while(0)
#endif
#ifdef __cplusplus
}
#endif
......
......@@ -213,6 +213,9 @@ typedef struct st_mysql_cond mysql_cond_t;
#define mysql_mutex_assert_not_owner(M) \
safe_mutex_assert_not_owner(&(M)->m_mutex)
#define mysql_mutex_setflags(M, F) \
safe_mutex_setflags(&(M)->m_mutex, (F))
/** Wrappers for instrumented prlock objects. */
#define mysql_prlock_assert_write_owner(M) \
......
......@@ -201,7 +201,7 @@ int safe_mutex_init(safe_mutex_t *mp,
/* Deadlock detection is initialised only lazily, on first use. */
mp->create_flags= safe_mutex_deadlock_detector ? MYF_NO_DEADLOCK_DETECTION : 0;
mp->create_flags= safe_mutex_deadlock_detector ? 0 : MYF_NO_DEADLOCK_DETECTION;
#ifdef SAFE_MUTEX_DETECT_DESTROY
/*
......
......@@ -41,17 +41,11 @@ Master_info::Master_info(bool is_slave_recovery)
bzero((char*) &file, sizeof(file));
mysql_mutex_init(key_master_info_run_lock, &run_lock, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_master_info_data_lock, &data_lock, MY_MUTEX_INIT_FAST);
mysql_mutex_setflags(&run_lock, MYF_NO_DEADLOCK_DETECTION);
mysql_mutex_setflags(&data_lock, MYF_NO_DEADLOCK_DETECTION);
mysql_cond_init(key_master_info_data_cond, &data_cond, NULL);
mysql_cond_init(key_master_info_start_cond, &start_cond, NULL);
mysql_cond_init(key_master_info_stop_cond, &stop_cond, NULL);
#ifdef SAFE_MUTEX
/* Define mutex order for locks to find wrong lock usage */
mysql_mutex_lock(&data_lock);
mysql_mutex_lock(&run_lock);
mysql_mutex_unlock(&run_lock);
mysql_mutex_unlock(&data_lock);
#endif
}
Master_info::~Master_info()
......
......@@ -3331,6 +3331,10 @@ pthread_handler_t handle_slave_sql(void *arg)
LINT_INIT(saved_master_log_pos);
LINT_INIT(saved_log_pos);
thd = new THD; // note that contructor of THD uses DBUG_ !
thd->thread_stack = (char*)&thd; // remember where our stack is
DBUG_ASSERT(rli->inited);
mysql_mutex_lock(&rli->run_lock);
DBUG_ASSERT(!rli->slave_running);
......@@ -3339,8 +3343,6 @@ pthread_handler_t handle_slave_sql(void *arg)
rli->events_till_abort = abort_slave_event_count;
#endif
thd = new THD; // note that contructor of THD uses DBUG_ !
thd->thread_stack = (char*)&thd; // remember where our stack is
rli->sql_thd= thd;
/* Inform waiting threads that slave has started */
......
......@@ -828,6 +828,11 @@ THD::THD()
mysql_mutex_init(key_LOCK_thd_data, &LOCK_thd_data, MY_MUTEX_INIT_FAST);
mysql_mutex_init(key_LOCK_wakeup_ready, &LOCK_wakeup_ready, MY_MUTEX_INIT_FAST);
mysql_cond_init(key_COND_wakeup_ready, &COND_wakeup_ready, 0);
/*
LOCK_thread_count goes before LOCK_thd_data - the former is called around
'delete thd', the latter - in THD::~THD
*/
mysql_mutex_record_order(&LOCK_thread_count, &LOCK_thd_data);
/* Variables with default values */
proc_info="login";
......
......@@ -1518,6 +1518,7 @@ static my_bool translog_buffer_init(struct st_translog_buffer *buffer, int num)
mysql_cond_init(key_TRANSLOG_BUFFER_prev_sent_to_disk_cond,
&buffer->prev_sent_to_disk_cond, 0))
DBUG_RETURN(1);
mysql_mutex_setflags(&buffer->mutex, MYF_NO_DEADLOCK_DETECTION);
buffer->is_closing_buffer= 0;
buffer->prev_sent_to_disk= LSN_IMPOSSIBLE;
buffer->prev_buffer_offset= LSN_IMPOSSIBLE;
......
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