35 #include "sync0arr.ic"
141 #ifdef UNIV_PFS_MUTEX
143 UNIV_INTERN mysql_pfs_key_t syn_arr_mutex_key;
146 #ifdef UNIV_SYNC_DEBUG
153 sync_array_detect_deadlock(
167 sync_array_get_nth_cell(
173 ut_a(n < arr->n_cells);
175 return(arr->
array + n);
193 mutex_enter(&(arr->
mutex));
214 mutex_exit(&(arr->
mutex));
242 memset(arr, 0x0,
sizeof(*arr));
246 memset(arr->
array, 0x0, sz);
255 mutex_create(syn_arr_mutex_key,
256 &arr->
mutex, SYNC_NO_ORDER_CHECK);
285 mutex_free(&(arr->
mutex));
307 sync_array_enter(arr);
309 for (i = 0; i < arr->
n_cells; i++) {
310 cell = sync_array_get_nth_cell(arr, i);
318 sync_array_exit(arr);
331 if (type == SYNC_MUTEX) {
333 }
else if (type == RW_LOCK_WAIT_EX) {
361 sync_array_enter(arr);
366 for (i = 0; i < arr->
n_cells; i++) {
367 cell = sync_array_get_nth_cell(arr, i);
374 if (type == SYNC_MUTEX) {
389 sync_array_exit(arr);
394 event = sync_cell_get_event(cell);
427 sync_array_enter(arr);
429 cell = sync_array_get_nth_cell(arr, index);
435 event = sync_cell_get_event(cell);
438 #ifdef UNIV_SYNC_DEBUG
445 rw_lock_debug_mutex_enter();
447 if (TRUE == sync_array_detect_deadlock(arr, cell, cell, 0)) {
449 fputs(
"########################################\n", stderr);
453 rw_lock_debug_mutex_exit();
455 sync_array_exit(arr);
466 sync_array_cell_print(
479 "--Thread %lu has waited at %s line %lu"
480 " for %.2f seconds the semaphore:\n",
485 if (type == SYNC_MUTEX) {
491 "Mutex at %p created file %s line %lu, lock var %lu\n"
492 #ifdef UNIV_SYNC_DEBUG
493 "Last time reserved in file %s line %lu, "
495 "waiters flag %lu\n",
498 #ifdef UNIV_SYNC_DEBUG
499 mutex->file_name, (ulong) mutex->line,
503 }
else if (type == RW_LOCK_EX
504 || type == RW_LOCK_WAIT_EX
505 || type == RW_LOCK_SHARED) {
507 fputs(type == RW_LOCK_EX ?
"X-lock on"
508 : type == RW_LOCK_WAIT_EX ?
"X-lock (wait_ex) on"
509 :
"S-lock on", file);
514 " RW-latch at %p created in file %s line %lu\n",
516 (ulong) rwlock->
cline);
518 if (writer != RW_LOCK_NOT_LOCKED) {
520 "a writer (thread id %lu) has"
521 " reserved it in mode %s",
525 :
" wait exclusive\n");
529 "number of readers %lu, waiters flag %lu, "
531 "Last time read locked in file %s line %lu\n"
532 "Last time write locked in file %s line %lu\n",
545 fputs(
"wait has ended\n", file);
549 #ifdef UNIV_SYNC_DEBUG
555 sync_array_find_thread(
563 for (i = 0; i < arr->
n_cells; i++) {
565 cell = sync_array_get_nth_cell(arr, i);
582 sync_array_deadlock_step(
605 new = sync_array_find_thread(arr, thread);
613 fputs(
"########################################\n"
614 "DEADLOCK of threads detected!\n", stderr);
619 ret = sync_array_detect_deadlock(arr, start,
new, depth);
634 sync_array_detect_deadlock(
646 rw_lock_debug_t*debug;
668 thread = mutex->thread_id;
678 ret = sync_array_deadlock_step(arr, start, thread, 0,
682 "Mutex %p owned by thread %lu file %s line %lu\n",
684 mutex->file_name, (ulong) mutex->line);
685 sync_array_cell_print(stderr, cell);
700 while (debug != NULL) {
702 thread = debug->thread_id;
704 if (((debug->lock_type == RW_LOCK_EX)
706 || ((debug->lock_type == RW_LOCK_WAIT_EX)
708 || (debug->lock_type == RW_LOCK_SHARED)) {
716 ret = sync_array_deadlock_step(
717 arr, start, thread, debug->pass,
721 fprintf(stderr,
"rw-lock %p ",
723 sync_array_cell_print(stderr, cell);
724 rw_lock_debug_print(debug);
739 while (debug != NULL) {
741 thread = debug->thread_id;
743 if ((debug->lock_type == RW_LOCK_EX)
744 || (debug->lock_type == RW_LOCK_WAIT_EX)) {
751 ret = sync_array_deadlock_step(
752 arr, start, thread, debug->pass,
777 sync_arr_cell_can_wake_up(
837 sync_array_enter(arr);
839 cell = sync_array_get_nth_cell(arr, index);
850 sync_array_exit(arr);
861 #ifdef HAVE_ATOMIC_BUILTINS
862 (void) os_atomic_increment_ulint(&arr->
sg_count, 1);
864 sync_array_enter(arr);
868 sync_array_exit(arr);
891 sync_array_enter(arr);
896 while (count < arr->n_reserved) {
898 cell = sync_array_get_nth_cell(arr, i);
906 if (sync_arr_cell_can_wake_up(cell)) {
908 event = sync_cell_get_event(cell);
915 sync_array_exit(arr);
928 ibool noticed = FALSE;
930 ulint fatal_timeout = srv_fatal_semaphore_wait_threshold;
939 fputs(
"InnoDB: Warning: a long semaphore wait:\n",
941 sync_array_cell_print(stderr, cell);
954 "InnoDB: ###### Starts InnoDB Monitor"
955 " for 30 secs to print diagnostic info:\n");
956 old_val = srv_print_innodb_monitor;
965 "InnoDB: Pending preads %lu, pwrites %lu\n",
969 srv_print_innodb_monitor = TRUE;
974 srv_print_innodb_monitor = old_val;
976 "InnoDB: ###### Diagnostic info printed"
977 " to the standard error stream\n");
987 sync_array_output_info(
998 "OS WAIT ARRAY INFO: reservation count %ld, signal count %ld\n",
1003 while (count < arr->n_reserved) {
1005 cell = sync_array_get_nth_cell(arr, i);
1009 sync_array_cell_print(file, cell);
1025 sync_array_enter(arr);
1027 sync_array_output_info(file, arr);
1029 sync_array_exit(arr);