summaryrefslogtreecommitdiff
path: root/sql/sql_class.h
diff options
context:
space:
mode:
authorunknown <guilhem@mysql.com>2004-07-31 22:33:20 +0200
committerunknown <guilhem@mysql.com>2004-07-31 22:33:20 +0200
commit00e7ec42795c08da55a22cc76d1e988c2a114098 (patch)
tree0f8a3d06ad26a2e3d61d38def3d87f5c2097ccaa /sql/sql_class.h
parent42ed0103c8cac51d84c9fdf339058a85667cd19a (diff)
downloadmariadb-git-00e7ec42795c08da55a22cc76d1e988c2a114098.tar.gz
Fix for:
Bug #4810 "deadlock with KILL when the victim was in a wait state" (I included mutex unlock into exit_cond() for future safety) and BUG#4827 "KILL while START SLAVE may lead to replication slave crash" sql/lock.cc: we did exit_cond() before unlock(LOCK_open), which led to deadlocks with THD::awake(). Fixing this. sql/log.cc: mutex unlock is now included in exit_cond() sql/repl_failsafe.cc: we did exit_cond() before unlock(LOCK_rpl_status), which led to deadlocks with THD::awake(). Fixing this. sql/slave.cc: we did exit_cond() before unlock(cond_lock), which led to deadlocks with THD::awake(). Fixing this. Fixing also that if killed while waiting for slave thread to start, we don't release the mutex (that caused a double release of the mutex => crash). sql/sql_class.h: comments about exit_cond()/enter_cond(). Mutex unlock is now included in exit_cond() so that it's always done in the good order. sql/sql_table.cc: unlock is now included in exit_cond().
Diffstat (limited to 'sql/sql_class.h')
-rw-r--r--sql/sql_class.h16
1 files changed, 10 insertions, 6 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h
index df246b42337..e646d33fe5d 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -537,12 +537,9 @@ public:
void awake(bool prepare_to_die);
/*
For enter_cond() / exit_cond() to work the mutex must be got before
- enter_cond() but released before exit_cond() (in 4.1, assertions will soon
- ensure this). Use must be:
- lock mutex; enter_cond(); ...; unlock mutex; exit_cond().
- If you don't do it this way, you will get a deadlock if another thread is
- doing a THD::awake() on you.
-
+ enter_cond() (in 4.1 an assertion will soon ensure this); this mutex is
+ then released by exit_cond(). Use must be:
+ lock mutex; enter_cond(); your code; exit_cond().
*/
inline const char* enter_cond(pthread_cond_t *cond, pthread_mutex_t* mutex,
const char* msg)
@@ -555,6 +552,13 @@ public:
}
inline void exit_cond(const char* old_msg)
{
+ /*
+ Putting the mutex unlock in exit_cond() ensures that
+ mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
+ locked (if that would not be the case, you'll get a deadlock if someone
+ does a THD::awake() on you).
+ */
+ pthread_mutex_unlock(mysys_var->current_mutex);
pthread_mutex_lock(&mysys_var->mutex);
mysys_var->current_mutex = 0;
mysys_var->current_cond = 0;