File tree Expand file tree Collapse file tree 4 files changed +28
-14
lines changed Expand file tree Collapse file tree 4 files changed +28
-14
lines changed Original file line number Diff line number Diff line change @@ -386,6 +386,7 @@ rw_lock_x_lock_func_nowait(
386
386
ulint line) /*!< in: line where requested */
387
387
{
388
388
ibool success;
389
+ ibool local_recursive= lock->recursive;
389
390
390
391
#ifdef INNODB_RW_LOCKS_USE_ATOMICS
391
392
success = os_compare_and_swap_lint(&lock->lock_word, X_LOCK_DECR, 0);
@@ -400,10 +401,14 @@ rw_lock_x_lock_func_nowait(
400
401
mutex_exit(&(lock->mutex));
401
402
402
403
#endif
404
+ /* Note: recursive must be loaded before writer_thread see
405
+ comment for rw_lock_set_writer_id_and_recursion_flag().
406
+ To achieve this we load it before os_compare_and_swap_lint(),
407
+ which implies full memory barrier in current implementation. */
403
408
if (success) {
404
409
rw_lock_set_writer_id_and_recursion_flag(lock, TRUE);
405
410
406
- } else if (lock->recursive
411
+ } else if (local_recursive
407
412
&& os_thread_eq(lock->writer_thread,
408
413
os_thread_get_curr_id())) {
409
414
/* Relock: this lock_word modification is safe since no other
Original file line number Diff line number Diff line change @@ -545,6 +545,8 @@ rw_lock_x_lock_low(
545
545
const char * file_name,/* !< in: file name where lock requested */
546
546
ulint line) /* !< in: line where requested */
547
547
{
548
+ ibool local_recursive= lock->recursive ;
549
+
548
550
if (rw_lock_lock_word_decr (lock, X_LOCK_DECR)) {
549
551
550
552
/* lock->recursive also tells us if the writer_thread
@@ -566,12 +568,12 @@ rw_lock_x_lock_low(
566
568
} else {
567
569
os_thread_id_t thread_id = os_thread_get_curr_id ();
568
570
569
- if (!pass) {
570
- os_rmb;
571
- }
572
-
573
- /* Decrement failed: relock or failed lock */
574
- if (!pass && lock-> recursive
571
+ /* Decrement failed: relock or failed lock
572
+ Note: recursive must be loaded before writer_thread see
573
+ comment for rw_lock_set_writer_id_and_recursion_flag().
574
+ To achieve this we load it before rw_lock_lock_word_decr(),
575
+ which implies full memory barrier in current implementation. */
576
+ if (!pass && local_recursive
575
577
&& os_thread_eq (lock->writer_thread , thread_id)) {
576
578
/* Relock */
577
579
if (lock->lock_word == 0 ) {
Original file line number Diff line number Diff line change @@ -511,6 +511,7 @@ rw_lock_x_lock_func_nowait(
511
511
ulint line) /*!< in: line where requested */
512
512
{
513
513
ibool success;
514
+ ibool local_recursive= lock->recursive;
514
515
515
516
#ifdef INNODB_RW_LOCKS_USE_ATOMICS
516
517
success = os_compare_and_swap_lint(&lock->lock_word, X_LOCK_DECR, 0);
@@ -525,10 +526,14 @@ rw_lock_x_lock_func_nowait(
525
526
mutex_exit(&(lock->mutex));
526
527
527
528
#endif
529
+ /* Note: recursive must be loaded before writer_thread see
530
+ comment for rw_lock_set_writer_id_and_recursion_flag().
531
+ To achieve this we load it before os_compare_and_swap_lint(),
532
+ which implies full memory barrier in current implementation. */
528
533
if (success) {
529
534
rw_lock_set_writer_id_and_recursion_flag(lock, TRUE);
530
535
531
- } else if (lock->recursive
536
+ } else if (local_recursive
532
537
&& os_thread_eq(lock->writer_thread,
533
538
os_thread_get_curr_id())) {
534
539
/* Relock: this lock_word modification is safe since no other
Original file line number Diff line number Diff line change @@ -694,6 +694,8 @@ rw_lock_x_lock_low(
694
694
const char * file_name,/* !< in: file name where lock requested */
695
695
ulint line) /* !< in: line where requested */
696
696
{
697
+ ibool local_recursive= lock->recursive ;
698
+
697
699
if (rw_lock_lock_word_decr (lock, X_LOCK_DECR)) {
698
700
699
701
/* lock->recursive also tells us if the writer_thread
@@ -715,12 +717,12 @@ rw_lock_x_lock_low(
715
717
} else {
716
718
os_thread_id_t thread_id = os_thread_get_curr_id ();
717
719
718
- if (!pass) {
719
- os_rmb;
720
- }
721
-
722
- /* Decrement failed: relock or failed lock */
723
- if (!pass && lock-> recursive
720
+ /* Decrement failed: relock or failed lock
721
+ Note: recursive must be loaded before writer_thread see
722
+ comment for rw_lock_set_writer_id_and_recursion_flag().
723
+ To achieve this we load it before rw_lock_lock_word_decr(),
724
+ which implies full memory barrier in current implementation. */
725
+ if (!pass && local_recursive
724
726
&& os_thread_eq (lock->writer_thread , thread_id)) {
725
727
/* Relock */
726
728
if (lock->lock_word == 0 ) {
You can’t perform that action at this time.
0 commit comments