00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00033 #pragma once
00034 #ifndef sync0sync_h
00035 #define sync0sync_h
00036
00037 #include "univ.i"
00038 #include "sync0types.h"
00039 #include "ut0lst.h"
00040 #include "ut0mem.h"
00041 #include "os0thread.h"
00042 #include "os0sync.h"
00043 #include "sync0arr.h"
00044
00045 #if defined(UNIV_DEBUG) && !defined(UNIV_HOTBACKUP)
00046 extern my_bool timed_mutexes;
00047 #endif
00048
00049 #ifdef HAVE_WINDOWS_ATOMICS
00050 typedef LONG lock_word_t;
00052 #else
00053 typedef byte lock_word_t;
00054 #endif
00055
00056 #if defined UNIV_PFS_MUTEX || defined UNIV_PFS_RWLOCK
00057
00058
00059
00060
00061
00062 # define PFS_NOT_INSTRUMENTED ULINT32_UNDEFINED
00063
00064 # define PFS_IS_INSTRUMENTED(key) ((key) != PFS_NOT_INSTRUMENTED)
00065
00066
00067
00068 # define PFS_SKIP_BUFFER_MUTEX_RWLOCK
00069
00070 #endif
00071
00072 #ifdef UNIV_PFS_MUTEX
00073
00074 extern mysql_pfs_key_t autoinc_mutex_key;
00075 extern mysql_pfs_key_t btr_search_enabled_mutex_key;
00076 extern mysql_pfs_key_t buffer_block_mutex_key;
00077 extern mysql_pfs_key_t buf_pool_mutex_key;
00078 extern mysql_pfs_key_t buf_pool_zip_mutex_key;
00079 extern mysql_pfs_key_t cache_last_read_mutex_key;
00080 extern mysql_pfs_key_t dict_foreign_err_mutex_key;
00081 extern mysql_pfs_key_t dict_sys_mutex_key;
00082 extern mysql_pfs_key_t file_format_max_mutex_key;
00083 extern mysql_pfs_key_t fil_system_mutex_key;
00084 extern mysql_pfs_key_t flush_list_mutex_key;
00085 extern mysql_pfs_key_t hash_table_mutex_key;
00086 extern mysql_pfs_key_t ibuf_bitmap_mutex_key;
00087 extern mysql_pfs_key_t ibuf_mutex_key;
00088 extern mysql_pfs_key_t ibuf_pessimistic_insert_mutex_key;
00089 extern mysql_pfs_key_t log_sys_mutex_key;
00090 extern mysql_pfs_key_t log_flush_order_mutex_key;
00091 extern mysql_pfs_key_t kernel_mutex_key;
00092 extern mysql_pfs_key_t commit_id_mutex_key;
00093 # ifdef UNIV_MEM_DEBUG
00094 extern mysql_pfs_key_t mem_hash_mutex_key;
00095 # endif
00096 extern mysql_pfs_key_t mem_pool_mutex_key;
00097 extern mysql_pfs_key_t mutex_list_mutex_key;
00098 extern mysql_pfs_key_t purge_sys_mutex_key;
00099 extern mysql_pfs_key_t recv_sys_mutex_key;
00100 extern mysql_pfs_key_t rseg_mutex_key;
00101 # ifdef UNIV_SYNC_DEBUG
00102 extern mysql_pfs_key_t rw_lock_debug_mutex_key;
00103 # endif
00104 extern mysql_pfs_key_t rw_lock_list_mutex_key;
00105 extern mysql_pfs_key_t rw_lock_mutex_key;
00106 extern mysql_pfs_key_t srv_dict_tmpfile_mutex_key;
00107 extern mysql_pfs_key_t srv_innodb_monitor_mutex_key;
00108 extern mysql_pfs_key_t srv_misc_tmpfile_mutex_key;
00109 extern mysql_pfs_key_t srv_monitor_file_mutex_key;
00110 extern mysql_pfs_key_t syn_arr_mutex_key;
00111 # ifdef UNIV_SYNC_DEBUG
00112 extern mysql_pfs_key_t sync_thread_mutex_key;
00113 # endif
00114 extern mysql_pfs_key_t trx_doublewrite_mutex_key;
00115 extern mysql_pfs_key_t thr_local_mutex_key;
00116 extern mysql_pfs_key_t trx_undo_mutex_key;
00117 #endif
00118
00119
00121 UNIV_INTERN
00122 void
00123 sync_init(void);
00124
00125
00127 UNIV_INTERN
00128 void
00129 sync_close(void);
00130
00131
00132 #undef mutex_free
00133
00134 #ifdef UNIV_PFS_MUTEX
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00157 # ifdef UNIV_DEBUG
00158 # ifdef UNIV_SYNC_DEBUG
00159 # define mutex_create(K, M, level) \
00160 pfs_mutex_create_func((K), (M), #M, (level), __FILE__, __LINE__)
00161 # else
00162 # define mutex_create(K, M, level) \
00163 pfs_mutex_create_func((K), (M), #M, __FILE__, __LINE__)
00164 # endif
00165 # else
00166 # define mutex_create(K, M, level) \
00167 pfs_mutex_create_func((K), (M), __FILE__, __LINE__)
00168 # endif
00169
00170 # define mutex_enter(M) \
00171 pfs_mutex_enter_func((M), __FILE__, __LINE__)
00172
00173 # define mutex_enter_nowait(M) \
00174 pfs_mutex_enter_nowait_func((M), __FILE__, __LINE__)
00175
00176 # define mutex_exit(M) pfs_mutex_exit_func(M)
00177
00178 # define mutex_free(M) pfs_mutex_free_func(M)
00179
00180 #else
00181
00182
00183
00184 # ifdef UNIV_DEBUG
00185 # ifdef UNIV_SYNC_DEBUG
00186 # define mutex_create(K, M, level) \
00187 mutex_create_func((M), #M, (level), __FILE__, __LINE__)
00188 # else
00189 # define mutex_create(K, M, level) \
00190 mutex_create_func((M), #M, __FILE__, __LINE__)
00191 # endif
00192 # else
00193 # define mutex_create(K, M, level) \
00194 mutex_create_func((M), __FILE__, __LINE__)
00195 # endif
00196
00197 # define mutex_enter(M) mutex_enter_func((M), __FILE__, __LINE__)
00198
00199 # define mutex_enter_nowait(M) \
00200 mutex_enter_nowait_func((M), __FILE__, __LINE__)
00201
00202 # define mutex_exit(M) mutex_exit_func(M)
00203
00204 # define mutex_free(M) mutex_free_func(M)
00205
00206 #endif
00207
00208
00213 UNIV_INTERN
00214 void
00215 mutex_create_func(
00216
00217 mutex_t* mutex,
00218 #ifdef UNIV_DEBUG
00219 const char* cmutex_name,
00220 # ifdef UNIV_SYNC_DEBUG
00221 ulint level,
00222 # endif
00223 #endif
00224 const char* cfile_name,
00225 ulint cline);
00227
00232 UNIV_INTERN
00233 void
00234 mutex_free_func(
00235
00236 mutex_t* mutex);
00237
00241
00242
00243 #define mutex_enter_fast(M) mutex_enter_func((M), __FILE__, __LINE__)
00244
00249 UNIV_INLINE
00250 void
00251 mutex_enter_func(
00252
00253 mutex_t* mutex,
00254 const char* file_name,
00255 ulint line);
00256
00261 UNIV_INTERN
00262 ulint
00263 mutex_enter_nowait_func(
00264
00265 mutex_t* mutex,
00266 const char* file_name,
00268 ulint line);
00269
00272 UNIV_INLINE
00273 void
00274 mutex_exit_func(
00275
00276 mutex_t* mutex);
00279 #ifdef UNIV_PFS_MUTEX
00280
00286 UNIV_INLINE
00287 void
00288 pfs_mutex_create_func(
00289
00290 PSI_mutex_key key,
00291 mutex_t* mutex,
00292 # ifdef UNIV_DEBUG
00293 const char* cmutex_name,
00294 # ifdef UNIV_SYNC_DEBUG
00295 ulint level,
00296 # endif
00297 # endif
00298 const char* cfile_name,
00299 ulint cline);
00300
00305 UNIV_INLINE
00306 void
00307 pfs_mutex_enter_func(
00308
00309 mutex_t* mutex,
00310 const char* file_name,
00311 ulint line);
00312
00318 UNIV_INLINE
00319 ulint
00320 pfs_mutex_enter_nowait_func(
00321
00322 mutex_t* mutex,
00323 const char* file_name,
00325 ulint line);
00326
00331 UNIV_INLINE
00332 void
00333 pfs_mutex_exit_func(
00334
00335 mutex_t* mutex);
00337
00342 UNIV_INLINE
00343 void
00344 pfs_mutex_free_func(
00345
00346 mutex_t* mutex);
00348 #endif
00349
00350 #ifdef UNIV_SYNC_DEBUG
00351
00355 UNIV_INTERN
00356 ibool
00357 sync_all_freed(void);
00358
00359 #endif
00360
00361
00362
00364 UNIV_INTERN
00365 void
00366 sync_print_wait_info(
00367
00368 FILE* file);
00369
00371 UNIV_INTERN
00372 void
00373 sync_print(
00374
00375 FILE* file);
00376 #ifdef UNIV_DEBUG
00377
00380 UNIV_INTERN
00381 ibool
00382 mutex_validate(
00383
00384 const mutex_t* mutex);
00385
00389 UNIV_INTERN
00390 ibool
00391 mutex_own(
00392
00393 const mutex_t* mutex)
00394 __attribute__((warn_unused_result));
00395 #endif
00396 #ifdef UNIV_SYNC_DEBUG
00397
00401 UNIV_INTERN
00402 void
00403 sync_thread_add_level(
00404
00405 void* latch,
00406 ulint level);
00408
00413 UNIV_INTERN
00414 ibool
00415 sync_thread_reset_level(
00416
00417 void* latch);
00418
00421 UNIV_INTERN
00422 ibool
00423 sync_thread_levels_empty(void);
00424
00425
00429 UNIV_INTERN
00430 void*
00431 sync_thread_levels_contains(
00432
00433 ulint level);
00435
00438 UNIV_INTERN
00439 void*
00440 sync_thread_levels_nonempty_gen(
00441
00442 ibool dict_mutex_allowed);
00446 #define sync_thread_levels_empty_gen(d) (!sync_thread_levels_nonempty_gen(d))
00447
00449 UNIV_INTERN
00450 void
00451 mutex_get_debug_info(
00452
00453 mutex_t* mutex,
00454 const char** file_name,
00455 ulint* line,
00456 os_thread_id_t* thread_id);
00458
00461 UNIV_INTERN
00462 ulint
00463 mutex_n_reserved(void);
00464
00465 #endif
00466
00469 UNIV_INLINE
00470 lock_word_t
00471 mutex_get_lock_word(
00472
00473 const mutex_t* mutex);
00474 #ifdef UNIV_SYNC_DEBUG
00475
00479 UNIV_INLINE
00480 ulint
00481 mutex_get_waiters(
00482
00483 const mutex_t* mutex);
00484 #endif
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609 #define SYNC_USER_TRX_LOCK 9999
00610 #define SYNC_NO_ORDER_CHECK 3000
00611
00612 #define SYNC_LEVEL_VARYING 2000
00613
00614
00615
00616
00617
00618 #define SYNC_TRX_I_S_RWLOCK 1910
00619
00620 #define SYNC_TRX_I_S_LAST_READ 1900
00621
00622 #define SYNC_FILE_FORMAT_TAG 1200
00623
00624 #define SYNC_DICT_OPERATION 1001
00625
00626
00627
00628 #define SYNC_DICT 1000
00629 #define SYNC_DICT_AUTOINC_MUTEX 999
00630 #define SYNC_DICT_HEADER 995
00631 #define SYNC_IBUF_HEADER 914
00632 #define SYNC_IBUF_PESS_INSERT_MUTEX 912
00633 #define SYNC_IBUF_MUTEX 910
00634
00635
00636
00637
00638 #define SYNC_INDEX_TREE 900
00639 #define SYNC_TREE_NODE_NEW 892
00640 #define SYNC_TREE_NODE_FROM_HASH 891
00641 #define SYNC_TREE_NODE 890
00642 #define SYNC_PURGE_SYS 810
00643 #define SYNC_PURGE_LATCH 800
00644 #define SYNC_TRX_UNDO 700
00645 #define SYNC_RSEG 600
00646 #define SYNC_RSEG_HEADER_NEW 591
00647 #define SYNC_RSEG_HEADER 590
00648 #define SYNC_TRX_UNDO_PAGE 570
00649 #define SYNC_EXTERN_STORAGE 500
00650 #define SYNC_FSP 400
00651 #define SYNC_FSP_PAGE 395
00652
00653
00654
00655 #define SYNC_IBUF_BITMAP_MUTEX 351
00656 #define SYNC_IBUF_BITMAP 350
00657
00658
00659
00660 #define SYNC_KERNEL 300
00661 #define SYNC_REC_LOCK 299
00662 #define SYNC_TRX_LOCK_HEAP 298
00663 #define SYNC_TRX_SYS_HEADER 290
00664 #define SYNC_LOG 170
00665 #define SYNC_LOG_FLUSH_ORDER 147
00666 #define SYNC_RECV 168
00667 #define SYNC_WORK_QUEUE 162
00668 #define SYNC_SEARCH_SYS_CONF 161
00669 #define SYNC_SEARCH_SYS 160
00670
00671
00672
00673
00674
00675 #define SYNC_COMMIT_ID_LOCK 159
00676 #define SYNC_BUF_POOL 150
00677 #define SYNC_BUF_BLOCK 146
00678 #define SYNC_BUF_FLUSH_LIST 145
00679 #define SYNC_DOUBLEWRITE 140
00680 #define SYNC_ANY_LATCH 135
00681 #define SYNC_THR_LOCAL 133
00682 #define SYNC_MEM_HASH 131
00683 #define SYNC_MEM_POOL 130
00684
00685
00686 #define RW_LOCK_NOT_LOCKED 350
00687 #define RW_LOCK_EX 351
00688 #define RW_LOCK_EXCLUSIVE 351
00689 #define RW_LOCK_SHARED 352
00690 #define RW_LOCK_WAIT_EX 353
00691 #define SYNC_MUTEX 354
00692
00693
00694
00695
00696
00698 struct mutex_struct {
00699 os_event_t event;
00700 volatile lock_word_t lock_word;
00704 #if !defined(HAVE_ATOMIC_BUILTINS)
00705 os_fast_mutex_t
00706 os_fast_mutex;
00708 #endif
00709 ulint waiters;
00713 UT_LIST_NODE_T(mutex_t) list;
00715 #ifdef UNIV_SYNC_DEBUG
00716 const char* file_name;
00717 ulint line;
00718 ulint level;
00719 #endif
00720 const char* cfile_name;
00721 ulint cline;
00722 #ifdef UNIV_DEBUG
00723 os_thread_id_t thread_id;
00725 ulint magic_n;
00727 # define MUTEX_MAGIC_N (ulint)979585
00728 #endif
00729 ulong count_os_wait;
00730 #ifdef UNIV_DEBUG
00731 ulong count_using;
00732 ulong count_spin_loop;
00733 ulong count_spin_rounds;
00734 ulong count_os_yield;
00735 ulonglong lspent_time;
00736 ulonglong lmax_spent_time;
00737 const char* cmutex_name;
00738 ulint mutex_type;
00739 #endif
00740 #ifdef UNIV_PFS_MUTEX
00741 struct PSI_mutex* pfs_psi;
00743 #endif
00744 };
00745
00748 extern sync_array_t* sync_primary_wait_array;
00749
00750
00755 #define SYNC_SPIN_ROUNDS srv_n_spin_wait_rounds
00756
00758 extern ib_int64_t mutex_exit_count;
00759
00760 #ifdef UNIV_SYNC_DEBUG
00761
00762 extern ibool sync_order_checks_on;
00763 #endif
00764
00766 extern ibool sync_initialized;
00767
00769 typedef UT_LIST_BASE_NODE_T(mutex_t) ut_list_base_node_t;
00771 extern ut_list_base_node_t mutex_list;
00772
00774 extern mutex_t mutex_list_mutex;
00775
00776
00777 #ifndef UNIV_NONINL
00778 #include "sync0sync.ic"
00779 #endif
00780
00781 #endif