|
1 | | -/* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. |
| 1 | +/* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 2 |
|
3 | 3 | This program is free software; you can redistribute it and/or modify |
4 | 4 | it under the terms of the GNU General Public License as published by |
|
238 | 238 | #endif |
239 | 239 | while (!thd->killed && !end_of_wait_condition) |
240 | 240 | mysql_cond_wait(&condition_variable, &mutex); |
| 241 | + mysql_mutex_unlock(&mutex); |
241 | 242 | thd->exit_cond(old_message); |
242 | 243 |
|
243 | 244 | Here some explanations: |
244 | 245 |
|
245 | 246 | thd->enter_cond() is used to register the condition variable and the |
246 | | - mutex in thd->mysys_var. This is done to allow the thread to be |
247 | | - interrupted (killed) from its sleep. Another thread can find the |
248 | | - condition variable to signal and mutex to use for synchronization in |
249 | | - this thread's THD::mysys_var. |
| 247 | + mutex in THD::current_cond/current_mutex. This is done to allow the |
| 248 | + thread to be interrupted (killed) from its sleep. Another thread can |
| 249 | + find the condition variable to signal and mutex to use for synchronization |
| 250 | + in this thread's THD. |
250 | 251 |
|
251 | 252 | thd->enter_cond() requires the mutex to be acquired in advance. |
252 | 253 |
|
253 | | - thd->exit_cond() unregisters the condition variable and mutex and |
254 | | - releases the mutex. |
| 254 | + thd->exit_cond() unregisters the condition variable and mutex. Requires |
| 255 | + the mutex to be released in advance. |
255 | 256 |
|
256 | 257 | If you want to have a Debug Sync point with the wait, please place it |
257 | 258 | behind enter_cond(). Only then you can safely decide, if the wait will |
|
280 | 281 | [DEBUG_SYNC(thd, "sync_point_name");] |
281 | 282 | mysql_cond_wait(&condition_variable, &mutex); |
282 | 283 | } |
| 284 | + mysql_mutex_unlock(&mutex); |
283 | 285 | thd->exit_cond(old_message); |
284 | 286 | } |
285 | 287 |
|
|
291 | 293 | condition variable. It would just set THD::killed. But if we would not |
292 | 294 | test it again, we would go asleep though we are killed. If the killing |
293 | 295 | thread would kill us when we are after the second test, but still |
294 | | - before sleeping, we hold the mutex, which is registered in mysys_var. |
| 296 | + before sleeping, we hold the mutex, which is registered in THD. |
295 | 297 | The killing thread would try to acquire the mutex before signaling |
296 | 298 | the condition variable. Since the mutex is only released implicitly in |
297 | 299 | mysql_cond_wait(), the signaling happens at the right place. We |
@@ -1903,19 +1905,13 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action) |
1903 | 1905 | mutex and cond. This would prohibit the use of DEBUG_SYNC |
1904 | 1906 | between other places of enter_cond() and exit_cond(). |
1905 | 1907 |
|
1906 | | - We need to check for existence of thd->mysys_var to also make |
1907 | | - it possible to use DEBUG_SYNC framework in scheduler when this |
1908 | | - variable has been set to NULL. |
| 1908 | + Note that we cannot lock LOCK_current_cond here. See comment |
| 1909 | + in THD::enter_cond(). |
1909 | 1910 | */ |
1910 | | - if (thd->mysys_var) |
1911 | | - { |
1912 | | - old_mutex= thd->mysys_var->current_mutex; |
1913 | | - old_cond= thd->mysys_var->current_cond; |
1914 | | - thd->mysys_var->current_mutex= &debug_sync_global.ds_mutex; |
1915 | | - thd->mysys_var->current_cond= &debug_sync_global.ds_cond; |
1916 | | - } |
1917 | | - else |
1918 | | - old_mutex= NULL; |
| 1911 | + old_mutex= thd->current_mutex; |
| 1912 | + old_cond= thd->current_cond; |
| 1913 | + thd->current_mutex= &debug_sync_global.ds_mutex; |
| 1914 | + thd->current_cond= &debug_sync_global.ds_cond; |
1919 | 1915 |
|
1920 | 1916 | set_timespec(&abstime, action->timeout); |
1921 | 1917 | DBUG_EXECUTE("debug_sync_exec", { |
@@ -1974,11 +1970,11 @@ static void debug_sync_execute(THD *thd, st_debug_sync_action *action) |
1974 | 1970 | mysql_mutex_unlock(&debug_sync_global.ds_mutex); |
1975 | 1971 | if (old_mutex) |
1976 | 1972 | { |
1977 | | - mysql_mutex_lock(&thd->mysys_var->mutex); |
1978 | | - thd->mysys_var->current_mutex= old_mutex; |
1979 | | - thd->mysys_var->current_cond= old_cond; |
| 1973 | + mysql_mutex_lock(&thd->LOCK_current_cond); |
| 1974 | + thd->current_mutex= old_mutex; |
| 1975 | + thd->current_cond= old_cond; |
| 1976 | + mysql_mutex_unlock(&thd->LOCK_current_cond); |
1980 | 1977 | debug_sync_thd_proc_info(thd, old_proc_info); |
1981 | | - mysql_mutex_unlock(&thd->mysys_var->mutex); |
1982 | 1978 | } |
1983 | 1979 | else |
1984 | 1980 | debug_sync_thd_proc_info(thd, old_proc_info); |
|
0 commit comments