drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
sync0sync.cc
1/*****************************************************************************
2
3Copyright (c) 1995, 2011, Innobase Oy. All Rights Reserved.
4Copyright (C) 2008, Google Inc.
5
6Portions of this file contain modifications contributed and copyrighted by
7Google, Inc. Those modifications are gratefully acknowledged and are described
8briefly in the InnoDB documentation. The contributions by Google are
9incorporated with their permission, and subject to the conditions contained in
10the file COPYING.Google.
11
12This program is free software; you can redistribute it and/or modify it under
13the terms of the GNU General Public License as published by the Free Software
14Foundation; version 2 of the License.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License along with
21this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22St, Fifth Floor, Boston, MA 02110-1301 USA
23
24*****************************************************************************/
25
26/**************************************************/
32
33#include "sync0sync.h"
34#ifdef UNIV_NONINL
35#include "sync0sync.ic"
36#endif
37
38#include "sync0rw.h"
39#include "buf0buf.h"
40#include "srv0srv.h"
41#include "buf0types.h"
42#include "os0sync.h" /* for HAVE_ATOMIC_BUILTINS */
43#ifdef UNIV_SYNC_DEBUG
44# include "srv0start.h" /* srv_is_being_started */
45#endif /* UNIV_SYNC_DEBUG */
46#include "ha_prototypes.h"
47
48/*
49 REASONS FOR IMPLEMENTING THE SPIN LOCK MUTEX
50 ============================================
51
52Semaphore operations can be slow. Therefore, we implement our own efficient
53spin lock mutex. Future operating systems may provide efficient spin locks, but
54we cannot count on that.
55
56Another reason for implementing a spin lock is that on multiprocessor systems
57it can be more efficient for a processor to run a loop waiting for the
58semaphore to be released than to switch to a different thread. A thread switch
59takes 25 us on both platforms mentioned above. See Gray and Reuter's book
60Transaction processing for background.
61
62How long should the spin loop last before suspending the thread? On a
63uniprocessor, spinning does not help at all, because if the thread owning the
64mutex is not executing, it cannot be released. Spinning actually wastes
65resources.
66
67On a multiprocessor, we do not know if the thread owning the mutex is
68executing or not. Thus it would make sense to spin as long as the operation
69guarded by the mutex would typically last assuming that the thread is
70executing. If the mutex is not released by that time, we may assume that the
71thread owning the mutex is not executing and suspend the waiting thread.
72
73A typical operation (where no i/o involved) guarded by a mutex or a read-write
74lock may last 1 - 20 us on the current Pentium platform. The longest
75operations are the binary searches on an index node.
76
77We conclude that the best choice is to set the spin time at 20 us. Then the
78system should work well on a multiprocessor. On a uniprocessor we have to
79make sure that thread swithches due to mutex collisions are not frequent,
80i.e., they do not happen every 100 us or so, because that wastes too much
81resources. If the thread switches are not frequent, the 20 us wasted in spin
82loop is not too much.
83
84Empirical studies on the effect of spin time should be done for different
85platforms.
86
87
88 IMPLEMENTATION OF THE MUTEX
89 ===========================
90
91For background, see Curt Schimmel's book on Unix implementation on modern
92architectures. The key points in the implementation are atomicity and
93serialization of memory accesses. The test-and-set instruction (XCHG in
94Pentium) must be atomic. As new processors may have weak memory models, also
95serialization of memory references may be necessary. The successor of Pentium,
96P6, has at least one mode where the memory model is weak. As far as we know,
97in Pentium all memory accesses are serialized in the program order and we do
98not have to worry about the memory model. On other processors there are
99special machine instructions called a fence, memory barrier, or storage
100barrier, which can be used to serialize the memory accesses to happen in
101program order relative to the fence instruction.
102
103Leslie Lamport has devised a "bakery algorithm" to implement a mutex without
104the atomic test-and-set, but his algorithm should be modified for weak memory
105models. We do not use Lamport's algorithm, because we guess it is slower than
106the atomic test-and-set.
107
108Our mutex implementation works as follows: After that we perform the atomic
109test-and-set instruction on the memory word. If the test returns zero, we
110know we got the lock first. If the test returns not zero, some other thread
111was quicker and got the lock: then we spin in a loop reading the memory word,
112waiting it to become zero. It is wise to just read the word in the loop, not
113perform numerous test-and-set instructions, because they generate memory
114traffic between the cache and the main memory. The read loop can just access
115the cache, saving bus bandwidth.
116
117If we cannot acquire the mutex lock in the specified time, we reserve a cell
118in the wait array, set the waiters byte in the mutex to 1. To avoid a race
119condition, after setting the waiters byte and before suspending the waiting
120thread, we still have to check that the mutex is reserved, because it may
121have happened that the thread which was holding the mutex has just released
122it and did not see the waiters byte set to 1, a case which would lead the
123other thread to an infinite wait.
124
125LEMMA 1: After a thread resets the event of a mutex (or rw_lock), some
126=======
127thread will eventually call os_event_set() on that particular event.
128Thus no infinite wait is possible in this case.
129
130Proof: After making the reservation the thread sets the waiters field in the
131mutex to 1. Then it checks that the mutex is still reserved by some thread,
132or it reserves the mutex for itself. In any case, some thread (which may be
133also some earlier thread, not necessarily the one currently holding the mutex)
134will set the waiters field to 0 in mutex_exit, and then call
135os_event_set() with the mutex as an argument.
136Q.E.D.
137
138LEMMA 2: If an os_event_set() call is made after some thread has called
139=======
140the os_event_reset() and before it starts wait on that event, the call
141will not be lost to the second thread. This is true even if there is an
142intervening call to os_event_reset() by another thread.
143Thus no infinite wait is possible in this case.
144
145Proof (non-windows platforms): os_event_reset() returns a monotonically
146increasing value of signal_count. This value is increased at every
147call of os_event_set() If thread A has called os_event_reset() followed
148by thread B calling os_event_set() and then some other thread C calling
149os_event_reset(), the is_set flag of the event will be set to FALSE;
150but now if thread A calls os_event_wait_low() with the signal_count
151value returned from the earlier call of os_event_reset(), it will
152return immediately without waiting.
153Q.E.D.
154
155Proof (windows): If there is a writer thread which is forced to wait for
156the lock, it may be able to set the state of rw_lock to RW_LOCK_WAIT_EX
157The design of rw_lock ensures that there is one and only one thread
158that is able to change the state to RW_LOCK_WAIT_EX and this thread is
159guaranteed to acquire the lock after it is released by the current
160holders and before any other waiter gets the lock.
161On windows this thread waits on a separate event i.e.: wait_ex_event.
162Since only one thread can wait on this event there is no chance
163of this event getting reset before the writer starts wait on it.
164Therefore, this thread is guaranteed to catch the os_set_event()
165signalled unconditionally at the release of the lock.
166Q.E.D. */
167
168#if defined(UNIV_DEBUG) && !defined(UNIV_HOTBACKUP)
169bool timed_mutexes;
170#endif /* UNIV_DEBUG && !UNIV_HOTBACKUP */
171
172/* Number of spin waits on mutexes: for performance monitoring */
173
176static ib_int64_t mutex_spin_round_count = 0;
179static ib_int64_t mutex_spin_wait_count = 0;
182static ib_int64_t mutex_os_wait_count = 0;
185UNIV_INTERN ib_int64_t mutex_exit_count = 0;
186
190
192UNIV_INTERN ibool sync_initialized = FALSE;
193
195typedef struct sync_level_struct sync_level_t;
197typedef struct sync_thread_struct sync_thread_t;
198
199#ifdef UNIV_SYNC_DEBUG
200
203
204UNIV_INTERN sync_thread_t* sync_thread_level_arrays;
205
207UNIV_INTERN mutex_t sync_thread_mutex;
208
209# ifdef UNIV_PFS_MUTEX
210UNIV_INTERN mysql_pfs_key_t sync_thread_mutex_key;
211# endif /* UNIV_PFS_MUTEX */
212#endif /* UNIV_SYNC_DEBUG */
213
215UNIV_INTERN ut_list_base_node_t mutex_list;
216
219
220#ifdef UNIV_PFS_MUTEX
221UNIV_INTERN mysql_pfs_key_t mutex_list_mutex_key;
222#endif /* UNIV_PFS_MUTEX */
223
224#ifdef UNIV_SYNC_DEBUG
226UNIV_INTERN ibool sync_order_checks_on = FALSE;
227#endif /* UNIV_SYNC_DEBUG */
228
230static const ulint SYNC_THREAD_N_LEVELS = 10000;
231
232typedef struct sync_arr_struct sync_arr_t;
233
236 ulint in_use;
237 ulint n_elems;
238 ulint max_elems;
239 ulint next_free;
241 sync_level_t* elems;
242};
243
250
253 void* latch;
256 ulint level;
263};
264
265/******************************************************************/
270UNIV_INTERN
271void
273/*==============*/
274 mutex_t* mutex,
275#ifdef UNIV_DEBUG
276 const char* cmutex_name,
277# ifdef UNIV_SYNC_DEBUG
278 ulint level,
279# endif /* UNIV_SYNC_DEBUG */
280#endif /* UNIV_DEBUG */
281 const char* cfile_name,
282 ulint cline)
283{
284#if defined(HAVE_ATOMIC_BUILTINS)
285 mutex_reset_lock_word(mutex);
286#else
287 os_fast_mutex_init(&(mutex->os_fast_mutex));
288 mutex->lock_word = 0;
289#endif
290 mutex->event = os_event_create(NULL);
291 mutex_set_waiters(mutex, 0);
292#ifdef UNIV_DEBUG
293 mutex->magic_n = MUTEX_MAGIC_N;
294#endif /* UNIV_DEBUG */
295#ifdef UNIV_SYNC_DEBUG
296 mutex->line = 0;
297 mutex->file_name = "not yet reserved";
298 mutex->level = level;
299#endif /* UNIV_SYNC_DEBUG */
300 mutex->cfile_name = cfile_name;
301 mutex->cline = cline;
302 mutex->count_os_wait = 0;
303#ifdef UNIV_DEBUG
304 mutex->cmutex_name= cmutex_name;
305 mutex->count_using= 0;
306 mutex->mutex_type= 0;
307 mutex->lspent_time= 0;
308 mutex->lmax_spent_time= 0;
309 mutex->count_spin_loop= 0;
310 mutex->count_spin_rounds= 0;
311 mutex->count_os_yield= 0;
312#endif /* UNIV_DEBUG */
313
314 /* Check that lock_word is aligned; this is important on Intel */
315 ut_ad(((ulint)(&(mutex->lock_word))) % 4 == 0);
316
317 /* NOTE! The very first mutexes are not put to the mutex list */
318
319 if ((mutex == &mutex_list_mutex)
320#ifdef UNIV_SYNC_DEBUG
321 || (mutex == &sync_thread_mutex)
322#endif /* UNIV_SYNC_DEBUG */
323 ) {
324
325 return;
326 }
327
328 mutex_enter(&mutex_list_mutex);
329
331 || UT_LIST_GET_FIRST(mutex_list)->magic_n == MUTEX_MAGIC_N);
332
333 UT_LIST_ADD_FIRST(list, mutex_list, mutex);
334
335 mutex_exit(&mutex_list_mutex);
336}
337
338/******************************************************************/
343UNIV_INTERN
344void
346/*============*/
347 mutex_t* mutex)
348{
349 ut_ad(mutex_validate(mutex));
350 ut_a(mutex_get_lock_word(mutex) == 0);
351 ut_a(mutex_get_waiters(mutex) == 0);
352
353#ifdef UNIV_MEM_DEBUG
354 if (mutex == &mem_hash_mutex) {
356 ut_ad(UT_LIST_GET_FIRST(mutex_list) == &mem_hash_mutex);
357 UT_LIST_REMOVE(list, mutex_list, mutex);
358 goto func_exit;
359 }
360#endif /* UNIV_MEM_DEBUG */
361
362 if (mutex != &mutex_list_mutex
363#ifdef UNIV_SYNC_DEBUG
364 && mutex != &sync_thread_mutex
365#endif /* UNIV_SYNC_DEBUG */
366 ) {
367
368 mutex_enter(&mutex_list_mutex);
369
370 ut_ad(!UT_LIST_GET_PREV(list, mutex)
371 || UT_LIST_GET_PREV(list, mutex)->magic_n
372 == MUTEX_MAGIC_N);
373 ut_ad(!UT_LIST_GET_NEXT(list, mutex)
374 || UT_LIST_GET_NEXT(list, mutex)->magic_n
375 == MUTEX_MAGIC_N);
376
377 UT_LIST_REMOVE(list, mutex_list, mutex);
378
379 mutex_exit(&mutex_list_mutex);
380 }
381
382 os_event_free(mutex->event);
383#ifdef UNIV_MEM_DEBUG
384func_exit:
385#endif /* UNIV_MEM_DEBUG */
386#if !defined(HAVE_ATOMIC_BUILTINS)
387 os_fast_mutex_free(&(mutex->os_fast_mutex));
388#endif
389 /* If we free the mutex protecting the mutex list (freeing is
390 not necessary), we have to reset the magic number AFTER removing
391 it from the list. */
392#ifdef UNIV_DEBUG
393 mutex->magic_n = 0;
394#endif /* UNIV_DEBUG */
395}
396
397/********************************************************************/
402UNIV_INTERN
403ulint
405/*====================*/
406 mutex_t* mutex,
407 const char* /*file_name __attribute__((unused))*/,
410 ulint /*line __attribute__((unused))*/)
412{
413 ut_ad(mutex_validate(mutex));
414
415 if (!mutex_test_and_set(mutex)) {
416
417 ut_d(mutex->thread_id = os_thread_get_curr_id());
418#ifdef UNIV_SYNC_DEBUG
419 mutex_set_debug_info(mutex, file_name, line);
420#endif
421
422 return(0); /* Succeeded! */
423 }
424
425 return(1);
426}
427
428#ifdef UNIV_DEBUG
429/******************************************************************/
432UNIV_INTERN
433ibool
434mutex_validate(
435/*===========*/
436 const mutex_t* mutex)
437{
438 ut_a(mutex);
439 ut_a(mutex->magic_n == MUTEX_MAGIC_N);
440
441 return(TRUE);
442}
443
444/******************************************************************/
448UNIV_INTERN
449ibool
450mutex_own(
451/*======*/
452 const mutex_t* mutex)
453{
454 ut_ad(mutex_validate(mutex));
455
456 return(mutex_get_lock_word(mutex) == 1
457 && os_thread_eq(mutex->thread_id, os_thread_get_curr_id()));
458}
459#endif /* UNIV_DEBUG */
460
461/******************************************************************/
463UNIV_INTERN
464void
465mutex_set_waiters(
466/*==============*/
467 mutex_t* mutex,
468 ulint n)
469{
470 volatile ulint* ptr; /* declared volatile to ensure that
471 the value is stored to memory */
472 ut_ad(mutex);
473
474 ptr = &(mutex->waiters);
475
476 *ptr = n; /* Here we assume that the write of a single
477 word in memory is atomic */
478}
479
480/******************************************************************/
484UNIV_INTERN
485void
486mutex_spin_wait(
487/*============*/
488 mutex_t* mutex,
489 const char* file_name,
491 ulint line)
492{
493 ulint index; /* index of the reserved wait cell */
494 ulint i; /* spin round count */
495#ifdef UNIV_DEBUG
496 ib_int64_t lstart_time = 0, lfinish_time; /* for timing os_wait */
497 ulint ltime_diff;
498 ulint sec;
499 ulint ms;
500 uint timer_started = 0;
501#endif /* UNIV_DEBUG */
502 ut_ad(mutex);
503
504 /* This update is not thread safe, but we don't mind if the count
505 isn't exact. Moved out of ifdef that follows because we are willing
506 to sacrifice the cost of counting this as the data is valuable.
507 Count the number of calls to mutex_spin_wait. */
508 mutex_spin_wait_count++;
509
510mutex_loop:
511
512 i = 0;
513
514 /* Spin waiting for the lock word to become zero. Note that we do
515 not have to assume that the read access to the lock word is atomic,
516 as the actual locking is always committed with atomic test-and-set.
517 In reality, however, all processors probably have an atomic read of
518 a memory word. */
519
520spin_loop:
521 ut_d(mutex->count_spin_loop++);
522
523 while (mutex_get_lock_word(mutex) != 0 && i < SYNC_SPIN_ROUNDS) {
524 if (srv_spin_wait_delay) {
525 ut_delay(ut_rnd_interval(0, srv_spin_wait_delay));
526 }
527
528 i++;
529 }
530
531 if (i == SYNC_SPIN_ROUNDS) {
532#ifdef UNIV_DEBUG
533 mutex->count_os_yield++;
534#ifndef UNIV_HOTBACKUP
535 if (timed_mutexes && timer_started == 0) {
536 ut_usectime(&sec, &ms);
537 lstart_time= (ib_int64_t)sec * 1000000 + ms;
538 timer_started = 1;
539 }
540#endif /* UNIV_HOTBACKUP */
541#endif /* UNIV_DEBUG */
543 }
544
545#ifdef UNIV_SRV_PRINT_LATCH_WAITS
546 fprintf(stderr,
547 "Thread %lu spin wait mutex at %p"
548 " cfile %s cline %lu rnds %lu\n",
549 (ulong) os_thread_pf(os_thread_get_curr_id()), (void*) mutex,
550 innobase_basename(mutex->cfile_name),
551 (ulong) mutex->cline, (ulong) i);
552#endif
553
554 mutex_spin_round_count += i;
555
556 ut_d(mutex->count_spin_rounds += i);
557
558 if (mutex_test_and_set(mutex) == 0) {
559 /* Succeeded! */
560
561 ut_d(mutex->thread_id = os_thread_get_curr_id());
562#ifdef UNIV_SYNC_DEBUG
563 mutex_set_debug_info(mutex, file_name, line);
564#endif
565
566 goto finish_timing;
567 }
568
569 /* We may end up with a situation where lock_word is 0 but the OS
570 fast mutex is still reserved. On FreeBSD the OS does not seem to
571 schedule a thread which is constantly calling pthread_mutex_trylock
572 (in mutex_test_and_set implementation). Then we could end up
573 spinning here indefinitely. The following 'i++' stops this infinite
574 spin. */
575
576 i++;
577
578 if (i < SYNC_SPIN_ROUNDS) {
579 goto spin_loop;
580 }
581
583 SYNC_MUTEX, file_name, line, &index);
584
585 /* The memory order of the array reservation and the change in the
586 waiters field is important: when we suspend a thread, we first
587 reserve the cell and then set waiters field to 1. When threads are
588 released in mutex_exit, the waiters field is first set to zero and
589 then the event is set to the signaled state. */
590
591 mutex_set_waiters(mutex, 1);
592
593 /* Try to reserve still a few times */
594 for (i = 0; i < 4; i++) {
595 if (mutex_test_and_set(mutex) == 0) {
596 /* Succeeded! Free the reserved wait cell */
597
599
600 ut_d(mutex->thread_id = os_thread_get_curr_id());
601#ifdef UNIV_SYNC_DEBUG
602 mutex_set_debug_info(mutex, file_name, line);
603#endif
604
605#ifdef UNIV_SRV_PRINT_LATCH_WAITS
606 fprintf(stderr, "Thread %lu spin wait succeeds at 2:"
607 " mutex at %p\n",
609 (void*) mutex);
610#endif
611
612 goto finish_timing;
613
614 /* Note that in this case we leave the waiters field
615 set to 1. We cannot reset it to zero, as we do not
616 know if there are other waiters. */
617 }
618 }
619
620 /* Now we know that there has been some thread holding the mutex
621 after the change in the wait array and the waiters field was made.
622 Now there is no risk of infinite wait on the event. */
623
624#ifdef UNIV_SRV_PRINT_LATCH_WAITS
625 fprintf(stderr,
626 "Thread %lu OS wait mutex at %p cfile %s cline %lu rnds %lu\n",
627 (ulong) os_thread_pf(os_thread_get_curr_id()), (void*) mutex,
628 innobase_basename(mutex->cfile_name),
629 (ulong) mutex->cline, (ulong) i);
630#endif
631
632 mutex_os_wait_count++;
633
634 mutex->count_os_wait++;
635#ifdef UNIV_DEBUG
636 /* !!!!! Sometimes os_wait can be called without os_thread_yield */
637#ifndef UNIV_HOTBACKUP
638 if (timed_mutexes == 1 && timer_started == 0) {
639 ut_usectime(&sec, &ms);
640 lstart_time= (ib_int64_t)sec * 1000000 + ms;
641 timer_started = 1;
642 }
643#endif /* UNIV_HOTBACKUP */
644#endif /* UNIV_DEBUG */
645
647 goto mutex_loop;
648
649finish_timing:
650#ifdef UNIV_DEBUG
651 if (timed_mutexes == 1 && timer_started==1) {
652 ut_usectime(&sec, &ms);
653 lfinish_time= (ib_int64_t)sec * 1000000 + ms;
654
655 ltime_diff= (ulint) (lfinish_time - lstart_time);
656 mutex->lspent_time += ltime_diff;
657
658 if (mutex->lmax_spent_time < ltime_diff) {
659 mutex->lmax_spent_time= ltime_diff;
660 }
661 }
662#endif /* UNIV_DEBUG */
663 return;
664}
665
666/******************************************************************/
668UNIV_INTERN
669void
670mutex_signal_object(
671/*================*/
672 mutex_t* mutex)
673{
674 mutex_set_waiters(mutex, 0);
675
676 /* The memory order of resetting the waiters field and
677 signaling the object is important. See LEMMA 1 above. */
678 os_event_set(mutex->event);
680}
681
682#ifdef UNIV_SYNC_DEBUG
683/******************************************************************/
685UNIV_INTERN
686void
687mutex_set_debug_info(
688/*=================*/
689 mutex_t* mutex,
690 const char* file_name,
691 ulint line)
692{
693 ut_ad(mutex);
694 ut_ad(file_name);
695
696 sync_thread_add_level(mutex, mutex->level);
697
698 mutex->file_name = file_name;
699 mutex->line = line;
700}
701
702/******************************************************************/
704UNIV_INTERN
705void
706mutex_get_debug_info(
707/*=================*/
708 mutex_t* mutex,
709 const char** file_name,
710 ulint* line,
711 os_thread_id_t* thread_id)
713{
714 ut_ad(mutex);
715
716 *file_name = mutex->file_name;
717 *line = mutex->line;
718 *thread_id = mutex->thread_id;
719}
720
721/******************************************************************/
723static
724void
725mutex_list_print_info(
726/*==================*/
727 FILE* file)
728{
729 mutex_t* mutex;
730 const char* file_name;
731 ulint line;
732 os_thread_id_t thread_id;
733 ulint count = 0;
734
735 fputs("----------\n"
736 "MUTEX INFO\n"
737 "----------\n", file);
738
739 mutex_enter(&mutex_list_mutex);
740
742
743 while (mutex != NULL) {
744 count++;
745
746 if (mutex_get_lock_word(mutex) != 0) {
747 mutex_get_debug_info(mutex, &file_name, &line,
748 &thread_id);
749 fprintf(file,
750 "Locked mutex: addr %p thread %ld"
751 " file %s line %ld\n",
752 (void*) mutex, os_thread_pf(thread_id),
753 file_name, line);
754 }
755
756 mutex = UT_LIST_GET_NEXT(list, mutex);
757 }
758
759 fprintf(file, "Total number of mutexes %ld\n", count);
760
761 mutex_exit(&mutex_list_mutex);
762}
763
764/******************************************************************/
767UNIV_INTERN
768ulint
769mutex_n_reserved(void)
770/*==================*/
771{
772 mutex_t* mutex;
773 ulint count = 0;
774
775 mutex_enter(&mutex_list_mutex);
776
777 for (mutex = UT_LIST_GET_FIRST(mutex_list);
778 mutex != NULL;
779 mutex = UT_LIST_GET_NEXT(list, mutex)) {
780
781 if (mutex_get_lock_word(mutex) != 0) {
782
783 count++;
784 }
785 }
786
787 mutex_exit(&mutex_list_mutex);
788
789 ut_a(count >= 1);
790
791 /* Subtract one, because this function itself was holding
792 one mutex (mutex_list_mutex) */
793
794 return(count - 1);
795}
796
797/******************************************************************/
801UNIV_INTERN
802ibool
803sync_all_freed(void)
804/*================*/
805{
806 return(mutex_n_reserved() + rw_lock_n_locked() == 0);
807}
808
809/******************************************************************/
812static
813sync_thread_t*
814sync_thread_level_arrays_find_slot(void)
815/*====================================*/
816
817{
818 ulint i;
820
822
823 for (i = 0; i < OS_THREAD_MAX_N; i++) {
824 sync_thread_t* slot;
825
826 slot = &sync_thread_level_arrays[i];
827
828 if (slot->levels && os_thread_eq(slot->id, id)) {
829
830 return(slot);
831 }
832 }
833
834 return(NULL);
835}
836
837/******************************************************************/
840static
841sync_thread_t*
842sync_thread_level_arrays_find_free(void)
843/*====================================*/
844
845{
846 ulint i;
847
848 for (i = 0; i < OS_THREAD_MAX_N; i++) {
849 sync_thread_t* slot;
850
851 slot = &sync_thread_level_arrays[i];
852
853 if (slot->levels == NULL) {
854
855 return(slot);
856 }
857 }
858
859 return(NULL);
860}
861
862/******************************************************************/
865static
866void
867sync_print_warning(
868/*===============*/
869 const sync_level_t* slot)
871{
872 mutex_t* mutex;
873
874 mutex = slot->latch;
875
876 if (mutex->magic_n == MUTEX_MAGIC_N) {
877 fprintf(stderr,
878 "Mutex created at %s %lu\n",
880 (ulong) mutex->cline);
881
882 if (mutex_get_lock_word(mutex) != 0) {
883 ulint line;
884 const char* file_name;
885 os_thread_id_t thread_id;
886
887 mutex_get_debug_info(
888 mutex, &file_name, &line, &thread_id);
889
890 fprintf(stderr,
891 "InnoDB: Locked mutex:"
892 " addr %p thread %ld file %s line %ld\n",
893 (void*) mutex, os_thread_pf(thread_id),
894 file_name, (ulong) line);
895 } else {
896 fputs("Not locked\n", stderr);
897 }
898 } else {
899 rw_lock_t* lock = slot->latch;
900
901 rw_lock_print(lock);
902 }
903}
904
905/******************************************************************/
909static
910ibool
911sync_thread_levels_g(
912/*=================*/
913 sync_arr_t* arr,
915 ulint limit,
916 ulint warn)
917{
918 ulint i;
919
920 for (i = 0; i < arr->n_elems; i++) {
921 const sync_level_t* slot;
922
923 slot = &arr->elems[i];
924
925 if (slot->latch != NULL && slot->level <= limit) {
926 if (warn) {
927 fprintf(stderr,
928 "InnoDB: sync levels should be"
929 " > %lu but a level is %lu\n",
930 (ulong) limit, (ulong) slot->level);
931 sync_print_warning(slot);
932 }
933
934 return(FALSE);
935
936 }
937 }
938
939 return(TRUE);
940}
941
942/******************************************************************/
945static
946const sync_level_t*
947sync_thread_levels_contain(
948/*=======================*/
949 sync_arr_t* arr,
951 ulint level)
952{
953 ulint i;
954
955 for (i = 0; i < arr->n_elems; i++) {
956 const sync_level_t* slot;
957
958 slot = &arr->elems[i];
959
960 if (slot->latch != NULL && slot->level == level) {
961 return(slot);
962 }
963 }
964
965 return(NULL);
966}
967
968/******************************************************************/
972UNIV_INTERN
973void*
974sync_thread_levels_contains(
975/*========================*/
976 ulint level)
978{
979 ulint i;
980 sync_arr_t* arr;
981 sync_thread_t* thread_slot;
982
983 if (!sync_order_checks_on) {
984
985 return(NULL);
986 }
987
988 mutex_enter(&sync_thread_mutex);
989
990 thread_slot = sync_thread_level_arrays_find_slot();
991
992 if (thread_slot == NULL) {
993
994 mutex_exit(&sync_thread_mutex);
995
996 return(NULL);
997 }
998
999 arr = thread_slot->levels;
1000
1001 for (i = 0; i < arr->n_elems; i++) {
1002 sync_level_t* slot;
1003
1004 slot = &arr->elems[i];
1005
1006 if (slot->latch != NULL && slot->level == level) {
1007
1008 mutex_exit(&sync_thread_mutex);
1009 return(slot->latch);
1010 }
1011 }
1012
1013 mutex_exit(&sync_thread_mutex);
1014
1015 return(NULL);
1016}
1017
1018/******************************************************************/
1021UNIV_INTERN
1022void*
1023sync_thread_levels_nonempty_gen(
1024/*============================*/
1025 ibool dict_mutex_allowed)
1029{
1030 ulint i;
1031 sync_arr_t* arr;
1032 sync_thread_t* thread_slot;
1033
1034 if (!sync_order_checks_on) {
1035
1036 return(NULL);
1037 }
1038
1039 mutex_enter(&sync_thread_mutex);
1040
1041 thread_slot = sync_thread_level_arrays_find_slot();
1042
1043 if (thread_slot == NULL) {
1044
1045 mutex_exit(&sync_thread_mutex);
1046
1047 return(NULL);
1048 }
1049
1050 arr = thread_slot->levels;
1051
1052 for (i = 0; i < arr->n_elems; ++i) {
1053 const sync_level_t* slot;
1054
1055 slot = &arr->elems[i];
1056
1057 if (slot->latch != NULL
1058 && (!dict_mutex_allowed
1059 || (slot->level != SYNC_DICT
1060 && slot->level != SYNC_DICT_OPERATION))) {
1061
1062 mutex_exit(&sync_thread_mutex);
1063 ut_error;
1064
1065 return(slot->latch);
1066 }
1067 }
1068
1069 mutex_exit(&sync_thread_mutex);
1070
1071 return(NULL);
1072}
1073
1074/******************************************************************/
1077UNIV_INTERN
1078ibool
1079sync_thread_levels_empty(void)
1080/*==========================*/
1081{
1082 return(sync_thread_levels_empty_gen(FALSE));
1083}
1084
1085/******************************************************************/
1089UNIV_INTERN
1090void
1091sync_thread_add_level(
1092/*==================*/
1093 void* latch,
1094 ulint level)
1096{
1097 ulint i;
1098 sync_level_t* slot;
1099 sync_arr_t* array;
1100 sync_thread_t* thread_slot;
1101
1102 if (!sync_order_checks_on) {
1103
1104 return;
1105 }
1106
1107 if ((latch == (void*)&sync_thread_mutex)
1108 || (latch == (void*)&mutex_list_mutex)
1109 || (latch == (void*)&rw_lock_debug_mutex)
1110 || (latch == (void*)&rw_lock_list_mutex)) {
1111
1112 return;
1113 }
1114
1115 if (level == SYNC_LEVEL_VARYING) {
1116
1117 return;
1118 }
1119
1120 mutex_enter(&sync_thread_mutex);
1121
1122 thread_slot = sync_thread_level_arrays_find_slot();
1123
1124 if (thread_slot == NULL) {
1125 ulint sz;
1126
1127 sz = sizeof(*array)
1128 + (sizeof(*array->elems) * SYNC_THREAD_N_LEVELS);
1129
1130 /* We have to allocate the level array for a new thread */
1131 array = calloc(sz, sizeof(char));
1132 ut_a(array != NULL);
1133
1134 array->next_free = ULINT_UNDEFINED;
1135 array->max_elems = SYNC_THREAD_N_LEVELS;
1136 array->elems = (sync_level_t*) &array[1];
1137
1138 thread_slot = sync_thread_level_arrays_find_free();
1139 thread_slot->levels = array;
1140 thread_slot->id = os_thread_get_curr_id();
1141 }
1142
1143 array = thread_slot->levels;
1144
1145 /* NOTE that there is a problem with _NODE and _LEAF levels: if the
1146 B-tree height changes, then a leaf can change to an internal node
1147 or the other way around. We do not know at present if this can cause
1148 unnecessary assertion failures below. */
1149
1150 switch (level) {
1151 case SYNC_NO_ORDER_CHECK:
1152 case SYNC_EXTERN_STORAGE:
1153 case SYNC_TREE_NODE_FROM_HASH:
1154 /* Do no order checking */
1155 break;
1156 case SYNC_TRX_SYS_HEADER:
1158 /* This is violated during trx_sys_create_rsegs()
1159 when creating additional rollback segments when
1160 upgrading in innobase_start_or_create_for_mysql(). */
1161 break;
1162 }
1163 case SYNC_MEM_POOL:
1164 case SYNC_MEM_HASH:
1165 case SYNC_RECV:
1166 case SYNC_WORK_QUEUE:
1167 case SYNC_LOG:
1168 case SYNC_LOG_FLUSH_ORDER:
1169 case SYNC_THR_LOCAL:
1170 case SYNC_ANY_LATCH:
1171 case SYNC_FILE_FORMAT_TAG:
1172 case SYNC_DOUBLEWRITE:
1173 case SYNC_SEARCH_SYS:
1174 case SYNC_SEARCH_SYS_CONF:
1175 case SYNC_TRX_LOCK_HEAP:
1176 case SYNC_KERNEL:
1177 case SYNC_IBUF_BITMAP_MUTEX:
1178 case SYNC_RSEG:
1179 case SYNC_TRX_UNDO:
1180 case SYNC_PURGE_LATCH:
1181 case SYNC_PURGE_QUEUE:
1182 case SYNC_DICT_AUTOINC_MUTEX:
1183 case SYNC_DICT_OPERATION:
1184 case SYNC_DICT_HEADER:
1185 case SYNC_TRX_I_S_RWLOCK:
1186 case SYNC_TRX_I_S_LAST_READ:
1187 if (!sync_thread_levels_g(array, level, TRUE)) {
1188 fprintf(stderr,
1189 "InnoDB: sync_thread_levels_g(array, %lu)"
1190 " does not hold!\n", level);
1191 ut_error;
1192 }
1193 break;
1194 case SYNC_BUF_FLUSH_LIST:
1195 case SYNC_BUF_POOL:
1196 /* We can have multiple mutexes of this type therefore we
1197 can only check whether the greater than condition holds. */
1198 if (!sync_thread_levels_g(array, level-1, TRUE)) {
1199 fprintf(stderr,
1200 "InnoDB: sync_thread_levels_g(array, %lu)"
1201 " does not hold!\n", level-1);
1202 ut_error;
1203 }
1204 break;
1205
1206 case SYNC_BUF_BLOCK:
1207 /* Either the thread must own the buffer pool mutex
1208 (buf_pool->mutex), or it is allowed to latch only ONE
1209 buffer block (block->mutex or buf_pool->zip_mutex). */
1210 if (!sync_thread_levels_g(array, level, FALSE)) {
1211 ut_a(sync_thread_levels_g(array, level - 1, TRUE));
1212 ut_a(sync_thread_levels_contain(array, SYNC_BUF_POOL));
1213 }
1214 break;
1215 case SYNC_REC_LOCK:
1216 if (sync_thread_levels_contain(array, SYNC_KERNEL)) {
1217 ut_a(sync_thread_levels_g(array, SYNC_REC_LOCK - 1,
1218 TRUE));
1219 } else {
1220 ut_a(sync_thread_levels_g(array, SYNC_REC_LOCK, TRUE));
1221 }
1222 break;
1223 case SYNC_IBUF_BITMAP:
1224 /* Either the thread must own the master mutex to all
1225 the bitmap pages, or it is allowed to latch only ONE
1226 bitmap page. */
1227 if (sync_thread_levels_contain(array,
1228 SYNC_IBUF_BITMAP_MUTEX)) {
1229 ut_a(sync_thread_levels_g(array, SYNC_IBUF_BITMAP - 1,
1230 TRUE));
1231 } else {
1232 /* This is violated during trx_sys_create_rsegs()
1233 when creating additional rollback segments when
1234 upgrading in innobase_start_or_create_for_mysql(). */
1236 || sync_thread_levels_g(array, SYNC_IBUF_BITMAP,
1237 TRUE));
1238 }
1239 break;
1240 case SYNC_FSP_PAGE:
1241 ut_a(sync_thread_levels_contain(array, SYNC_FSP));
1242 break;
1243 case SYNC_FSP:
1244 ut_a(sync_thread_levels_contain(array, SYNC_FSP)
1245 || sync_thread_levels_g(array, SYNC_FSP, TRUE));
1246 break;
1247 case SYNC_TRX_UNDO_PAGE:
1248 /* Purge is allowed to read in as many UNDO pages as it likes,
1249 there was a bogus rule here earlier that forced the caller to
1250 acquire the purge_sys_t::mutex. The purge mutex did not really
1251 protect anything because it was only ever acquired by the
1252 single purge thread. The purge thread can read the UNDO pages
1253 without any covering mutex. */
1254
1255 ut_a(sync_thread_levels_contain(array, SYNC_TRX_UNDO)
1256 || sync_thread_levels_contain(array, SYNC_RSEG)
1257 || sync_thread_levels_g(array, level - 1, TRUE));
1258 break;
1259 case SYNC_RSEG_HEADER:
1260 ut_a(sync_thread_levels_contain(array, SYNC_RSEG));
1261 break;
1262 case SYNC_RSEG_HEADER_NEW:
1263 ut_a(sync_thread_levels_contain(array, SYNC_KERNEL)
1264 && sync_thread_levels_contain(array, SYNC_FSP_PAGE));
1265 break;
1266 case SYNC_TREE_NODE:
1267 ut_a(sync_thread_levels_contain(array, SYNC_INDEX_TREE)
1268 || sync_thread_levels_contain(array, SYNC_DICT_OPERATION)
1269 || sync_thread_levels_g(array, SYNC_TREE_NODE - 1, TRUE));
1270 break;
1271 case SYNC_TREE_NODE_NEW:
1272 ut_a(sync_thread_levels_contain(array, SYNC_FSP_PAGE)
1273 || sync_thread_levels_contain(array, SYNC_IBUF_MUTEX));
1274 break;
1275 case SYNC_INDEX_TREE:
1276 if (sync_thread_levels_contain(array, SYNC_IBUF_MUTEX)
1277 && sync_thread_levels_contain(array, SYNC_FSP)) {
1278 ut_a(sync_thread_levels_g(array, SYNC_FSP_PAGE - 1,
1279 TRUE));
1280 } else {
1281 ut_a(sync_thread_levels_g(array, SYNC_TREE_NODE - 1,
1282 TRUE));
1283 }
1284 break;
1285 case SYNC_IBUF_MUTEX:
1286 ut_a(sync_thread_levels_g(array, SYNC_FSP_PAGE - 1, TRUE));
1287 break;
1288 case SYNC_IBUF_PESS_INSERT_MUTEX:
1289 ut_a(sync_thread_levels_g(array, SYNC_FSP - 1, TRUE));
1290 ut_a(!sync_thread_levels_contain(array, SYNC_IBUF_MUTEX));
1291 break;
1292 case SYNC_IBUF_HEADER:
1293 ut_a(sync_thread_levels_g(array, SYNC_FSP - 1, TRUE));
1294 ut_a(!sync_thread_levels_contain(array, SYNC_IBUF_MUTEX));
1295 ut_a(!sync_thread_levels_contain(array,
1296 SYNC_IBUF_PESS_INSERT_MUTEX));
1297 break;
1298 case SYNC_DICT:
1299#ifdef UNIV_DEBUG
1300 ut_a(buf_debug_prints
1301 || sync_thread_levels_g(array, SYNC_DICT, TRUE));
1302#else /* UNIV_DEBUG */
1303 ut_a(sync_thread_levels_g(array, SYNC_DICT, TRUE));
1304#endif /* UNIV_DEBUG */
1305 break;
1306 default:
1307 ut_error;
1308 }
1309
1310 if (array->next_free == ULINT_UNDEFINED) {
1311 ut_a(array->n_elems < array->max_elems);
1312
1313 i = array->n_elems++;
1314 } else {
1315 i = array->next_free;
1316 array->next_free = array->elems[i].level;
1317 }
1318
1319 ut_a(i < array->n_elems);
1320 ut_a(i != ULINT_UNDEFINED);
1321
1322 ++array->in_use;
1323
1324 slot = &array->elems[i];
1325
1326 ut_a(slot->latch == NULL);
1327
1328 slot->latch = latch;
1329 slot->level = level;
1330
1331 mutex_exit(&sync_thread_mutex);
1332}
1333
1334/******************************************************************/
1339UNIV_INTERN
1340ibool
1341sync_thread_reset_level(
1342/*====================*/
1343 void* latch)
1344{
1345 sync_arr_t* array;
1346 sync_thread_t* thread_slot;
1347 ulint i;
1348
1349 if (!sync_order_checks_on) {
1350
1351 return(FALSE);
1352 }
1353
1354 if ((latch == (void*)&sync_thread_mutex)
1355 || (latch == (void*)&mutex_list_mutex)
1356 || (latch == (void*)&rw_lock_debug_mutex)
1357 || (latch == (void*)&rw_lock_list_mutex)) {
1358
1359 return(FALSE);
1360 }
1361
1362 mutex_enter(&sync_thread_mutex);
1363
1364 thread_slot = sync_thread_level_arrays_find_slot();
1365
1366 if (thread_slot == NULL) {
1367
1368 ut_error;
1369
1370 mutex_exit(&sync_thread_mutex);
1371 return(FALSE);
1372 }
1373
1374 array = thread_slot->levels;
1375
1376 for (i = 0; i < array->n_elems; i++) {
1377 sync_level_t* slot;
1378
1379 slot = &array->elems[i];
1380
1381 if (slot->latch != latch) {
1382 continue;
1383 }
1384
1385 slot->latch = NULL;
1386
1387 /* Update the free slot list. See comment in sync_level_t
1388 for the level field. */
1389 slot->level = array->next_free;
1390 array->next_free = i;
1391
1392 ut_a(array->in_use >= 1);
1393 --array->in_use;
1394
1395 /* If all cells are idle then reset the free
1396 list. The assumption is that this will save
1397 time when we need to scan up to n_elems. */
1398
1399 if (array->in_use == 0) {
1400 array->n_elems = 0;
1401 array->next_free = ULINT_UNDEFINED;
1402 }
1403
1404 mutex_exit(&sync_thread_mutex);
1405
1406 return(TRUE);
1407 }
1408
1409 if (((mutex_t*) latch)->magic_n != MUTEX_MAGIC_N) {
1410 rw_lock_t* rw_lock;
1411
1412 rw_lock = (rw_lock_t*) latch;
1413
1414 if (rw_lock->level == SYNC_LEVEL_VARYING) {
1415 mutex_exit(&sync_thread_mutex);
1416
1417 return(TRUE);
1418 }
1419 }
1420
1421 ut_error;
1422
1423 mutex_exit(&sync_thread_mutex);
1424
1425 return(FALSE);
1426}
1427#endif /* UNIV_SYNC_DEBUG */
1428
1429/******************************************************************/
1431UNIV_INTERN
1432void
1434/*===========*/
1435{
1436 ut_a(sync_initialized == FALSE);
1437
1438 sync_initialized = TRUE;
1439
1440 /* Create the primary system wait array which is protected by an OS
1441 mutex */
1442
1445#ifdef UNIV_SYNC_DEBUG
1446 /* Create the thread latch level array where the latch levels
1447 are stored for each OS thread */
1448
1449 sync_thread_level_arrays = calloc(
1450 sizeof(sync_thread_t), OS_THREAD_MAX_N);
1451 ut_a(sync_thread_level_arrays != NULL);
1452
1453#endif /* UNIV_SYNC_DEBUG */
1454 /* Init the mutex list and create the mutex to protect it. */
1455
1457 mutex_create(mutex_list_mutex_key, &mutex_list_mutex,
1458 SYNC_NO_ORDER_CHECK);
1459#ifdef UNIV_SYNC_DEBUG
1460 mutex_create(sync_thread_mutex_key, &sync_thread_mutex,
1461 SYNC_NO_ORDER_CHECK);
1462#endif /* UNIV_SYNC_DEBUG */
1463
1464 /* Init the rw-lock list and create the mutex to protect it. */
1465
1466 UT_LIST_INIT(rw_lock_list);
1467 mutex_create(rw_lock_list_mutex_key, &rw_lock_list_mutex,
1468 SYNC_NO_ORDER_CHECK);
1469
1470#ifdef UNIV_SYNC_DEBUG
1471 mutex_create(rw_lock_debug_mutex_key, &rw_lock_debug_mutex,
1472 SYNC_NO_ORDER_CHECK);
1473
1474 rw_lock_debug_event = os_event_create(NULL);
1475 rw_lock_debug_waiters = FALSE;
1476#endif /* UNIV_SYNC_DEBUG */
1477}
1478
1479#ifdef UNIV_SYNC_DEBUG
1480/******************************************************************/
1482static
1483void
1484sync_thread_level_arrays_free(void)
1485/*===============================*/
1486
1487{
1488 ulint i;
1489
1490 for (i = 0; i < OS_THREAD_MAX_N; i++) {
1491 sync_thread_t* slot;
1492
1493 slot = &sync_thread_level_arrays[i];
1494
1495 /* If this slot was allocated then free the slot memory too. */
1496 if (slot->levels != NULL) {
1497 free(slot->levels);
1498 slot->levels = NULL;
1499 }
1500 }
1501
1502 free(sync_thread_level_arrays);
1503 sync_thread_level_arrays = NULL;
1504}
1505#endif /* UNIV_SYNC_DEBUG */
1506
1507/******************************************************************/
1510UNIV_INTERN
1511void
1513/*===========*/
1514{
1515 mutex_t* mutex;
1516
1518
1519 for (mutex = UT_LIST_GET_FIRST(mutex_list);
1520 mutex != NULL;
1521 /* No op */) {
1522
1523#ifdef UNIV_MEM_DEBUG
1524 if (mutex == &mem_hash_mutex) {
1525 mutex = UT_LIST_GET_NEXT(list, mutex);
1526 continue;
1527 }
1528#endif /* UNIV_MEM_DEBUG */
1529
1530 mutex_free(mutex);
1531
1533 }
1534
1535 mutex_free(&mutex_list_mutex);
1536#ifdef UNIV_SYNC_DEBUG
1537 mutex_free(&sync_thread_mutex);
1538
1539 /* Switch latching order checks on in sync0sync.c */
1540 sync_order_checks_on = FALSE;
1541
1542 sync_thread_level_arrays_free();
1543#endif /* UNIV_SYNC_DEBUG */
1544
1545 sync_initialized = FALSE;
1546}
1547
1548/*******************************************************************/
1550UNIV_INTERN
1551void
1553/*=================*/
1554 FILE* file)
1555{
1556#ifdef UNIV_SYNC_DEBUG
1557 fprintf(file, "Mutex exits %llu, rws exits %llu, rwx exits %llu\n",
1559#endif
1560
1561 fprintf(file,
1562 "Mutex spin waits %" PRId64 ", rounds %" PRId64 ", "
1563 "OS waits %" PRId64 "\n"
1564 "RW-shared spins %" PRId64 ", rounds %" PRId64 ", OS waits %" PRId64 ";"
1565 " RW-excl spins %" PRId64 ", rounds %" PRId64 ", OS waits %" PRId64 "\n",
1566 mutex_spin_wait_count,
1567 mutex_spin_round_count,
1568 mutex_os_wait_count,
1575
1576 fprintf(file,
1577 "Spin rounds per wait: %.2f mutex, %.2f RW-shared, "
1578 "%.2f RW-excl\n",
1579 (double) mutex_spin_round_count /
1580 (mutex_spin_wait_count ? mutex_spin_wait_count : 1),
1581 (double) rw_s_spin_round_count /
1583 (double) rw_x_spin_round_count /
1585}
1586
1587/*******************************************************************/
1589UNIV_INTERN
1590void
1592/*=======*/
1593 FILE* file)
1594{
1595#ifdef UNIV_SYNC_DEBUG
1596 mutex_list_print_info(file);
1597
1598 rw_lock_list_print_info(file);
1599#endif /* UNIV_SYNC_DEBUG */
1600
1602
1604}
const char * innobase_basename(const char *path_name)
UNIV_INTERN void os_fast_mutex_free(os_fast_mutex_t *fast_mutex)
Definition os0sync.cc:930
UNIV_INTERN os_event_t os_event_create(const char *name)
Definition os0sync.cc:365
UNIV_INTERN void os_event_set(os_event_t event)
Definition os0sync.cc:434
UNIV_INTERN void os_fast_mutex_init(os_fast_mutex_t *fast_mutex)
Definition os0sync.cc:871
UNIV_INTERN void os_event_free(os_event_t event)
Definition os0sync.cc:535
UNIV_INTERN void os_thread_yield(void)
Definition os0thread.cc:244
os_thread_t os_thread_id_t
Definition os0thread.h:53
UNIV_INTERN ibool os_thread_eq(os_thread_id_t a, os_thread_id_t b)
Definition os0thread.cc:46
UNIV_INTERN os_thread_id_t os_thread_get_curr_id(void)
Definition os0thread.cc:93
UNIV_INTERN ulint os_thread_pf(os_thread_id_t a)
Definition os0thread.cc:72
ibool srv_is_being_started
Definition srv0start.cc:116
os_event_t event
Definition sync0sync.h:678
ulint waiters
Definition sync0sync.h:688
const char * cfile_name
Definition sync0sync.h:699
volatile lock_word_t lock_word
Definition sync0sync.h:679
ulong count_os_wait
Definition sync0sync.h:708
sync_level_t * elems
Definition sync0sync.cc:241
os_thread_id_t id
Definition sync0sync.cc:246
sync_arr_t * levels
Definition sync0sync.cc:247
UNIV_INTERN void sync_array_object_signalled(sync_array_t *arr)
Definition sync0arr.cc:852
UNIV_INTERN void sync_array_wait_event(sync_array_t *arr, ulint index)
Definition sync0arr.cc:418
UNIV_INTERN void sync_array_print_info(FILE *file, sync_array_t *arr)
Definition sync0arr.cc:1047
UNIV_INTERN void sync_array_reserve_cell(sync_array_t *arr, void *object, ulint type, const char *file, ulint line, ulint *index)
Definition sync0arr.cc:346
#define SYNC_ARRAY_OS_MUTEX
Definition sync0arr.h:41
UNIV_INTERN void sync_array_free_cell(sync_array_t *arr, ulint index)
Definition sync0arr.cc:825
UNIV_INTERN sync_array_t * sync_array_create(ulint n_cells, ulint protection)
Definition sync0arr.cc:228
UNIV_INTERN void sync_array_free(sync_array_t *arr)
Definition sync0arr.cc:269
struct sync_array_struct sync_array_t
Definition sync0arr.h:38
ib_int64_t rw_x_spin_round_count
Definition sync0rw.cc:158
ib_int64_t rw_s_spin_wait_count
Definition sync0rw.cc:140
ib_int64_t rw_s_os_wait_count
Definition sync0rw.cc:147
ib_int64_t rw_s_spin_round_count
Definition sync0rw.cc:143
ib_int64_t rw_x_spin_wait_count
Definition sync0rw.cc:155
ib_int64_t rw_s_exit_count
Definition sync0rw.cc:151
ib_int64_t rw_x_exit_count
Definition sync0rw.cc:166
ib_int64_t rw_x_os_wait_count
Definition sync0rw.cc:162
UNIV_INTERN void sync_close(void)
UNIV_INTERN ulint mutex_enter_nowait_func(mutex_t *mutex, const char *file_name, ulint line)
Definition sync0sync.cc:404
#define SYNC_SPIN_ROUNDS
Definition sync0sync.h:734
mutex_t mutex_list_mutex
Definition sync0sync.cc:218
ibool sync_initialized
Definition sync0sync.cc:192
UNIV_INTERN void sync_print(FILE *file)
UNIV_INTERN void mutex_create_func(mutex_t *mutex, const char *cfile_name, ulint cline)
Definition sync0sync.cc:272
UNIV_INTERN void sync_init(void)
ut_list_base_node_t mutex_list
Definition sync0sync.cc:215
ib_int64_t mutex_exit_count
Definition sync0sync.cc:185
UNIV_INLINE lock_word_t mutex_get_lock_word(const mutex_t *mutex)
sync_array_t * sync_primary_wait_array
Definition sync0sync.cc:189
UNIV_INTERN void mutex_free_func(mutex_t *mutex)
Definition sync0sync.cc:345
UNIV_INTERN void sync_print_wait_info(FILE *file)
#define mutex_t
Definition sync0types.h:31
#define ut_error
Definition ut0dbg.h:115
#define ut_ad(EXPR)
Definition ut0dbg.h:127
#define ut_d(EXPR)
Definition ut0dbg.h:129
#define ut_a(EXPR)
Definition ut0dbg.h:105
#define UT_LIST_GET_LEN(BASE)
Definition ut0lst.h:216
#define UT_LIST_REMOVE(NAME, BASE, N)
Definition ut0lst.h:177
#define UT_LIST_GET_FIRST(BASE)
Definition ut0lst.h:223
#define UT_LIST_GET_PREV(NAME, N)
Definition ut0lst.h:208
#define UT_LIST_ADD_FIRST(NAME, BASE, N)
Definition ut0lst.h:96
#define UT_LIST_GET_NEXT(NAME, N)
Definition ut0lst.h:200
#define UT_LIST_INIT(BASE)
Definition ut0lst.h:83
UNIV_INLINE ulint ut_rnd_interval(ulint low, ulint high)
UNIV_INTERN int ut_usectime(ulint *sec, ulint *ms)
Definition ut0ut.cc:145
UNIV_INTERN ulint ut_delay(ulint delay)
Definition ut0ut.cc:411