18
18
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20
20
You should have received a copy of the GNU General Public License along with
21
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22
St, Fifth Floor, Boston, MA 02110-1301 USA
21
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22
Place, Suite 330, Boston, MA 02111-1307 USA
24
24
*****************************************************************************/
315
303
/******************************************************************//**
316
NOTE! Use the corresponding macro mutex_free(), not directly this function!
317
304
Calling this function is obligatory only if the memory buffer containing
318
305
the mutex is freed. Removes a mutex object from the mutex list. The mutex
319
306
is checked to be in the reset state. */
324
311
mutex_t* mutex) /*!< in: mutex */
326
313
ut_ad(mutex_validate(mutex));
327
314
ut_a(mutex_get_lock_word(mutex) == 0);
328
315
ut_a(mutex_get_waiters(mutex) == 0);
330
#ifdef UNIV_MEM_DEBUG
331
if (mutex == &mem_hash_mutex) {
332
ut_ad(UT_LIST_GET_LEN(mutex_list) == 1);
333
ut_ad(UT_LIST_GET_FIRST(mutex_list) == &mem_hash_mutex);
334
UT_LIST_REMOVE(list, mutex_list, mutex);
337
#endif /* UNIV_MEM_DEBUG */
339
317
if (mutex != &mutex_list_mutex
340
318
#ifdef UNIV_SYNC_DEBUG
341
319
&& mutex != &sync_thread_mutex
972
942
/******************************************************************//**
973
Checks if the level array for the current thread contains a
974
mutex or rw-latch at the specified level.
975
@return a matching latch, or NULL if not found */
978
sync_thread_levels_contains(
979
/*========================*/
980
ulint level) /*!< in: latching order level
984
sync_thread_t* thread_slot;
988
if (!sync_order_checks_on) {
993
mutex_enter(&sync_thread_mutex);
995
thread_slot = sync_thread_level_arrays_find_slot();
997
if (thread_slot == NULL) {
999
mutex_exit(&sync_thread_mutex);
1004
arr = thread_slot->levels;
1006
for (i = 0; i < SYNC_THREAD_N_LEVELS; i++) {
1008
slot = sync_thread_levels_get_nth(arr, i);
1010
if (slot->latch != NULL && slot->level == level) {
1012
mutex_exit(&sync_thread_mutex);
1013
return(slot->latch);
1017
mutex_exit(&sync_thread_mutex);
1022
/******************************************************************//**
1023
943
Checks that the level array for the current thread is empty.
1024
@return a latch, or NULL if empty except the exceptions specified below */
944
@return TRUE if empty except the exceptions specified below */
1027
sync_thread_levels_nonempty_gen(
1028
/*============================*/
947
sync_thread_levels_empty_gen(
948
/*=========================*/
1029
949
ibool dict_mutex_allowed) /*!< in: TRUE if dictionary mutex is
1030
950
allowed to be owned by the thread,
1031
951
also purge_is_running mutex is
1155
1075
case SYNC_TREE_NODE_FROM_HASH:
1156
1076
/* Do no order checking */
1158
case SYNC_TRX_SYS_HEADER:
1159
if (srv_is_being_started) {
1160
/* This is violated during trx_sys_create_rsegs()
1161
when creating additional rollback segments when
1162
upgrading in innobase_start_or_create_for_mysql(). */
1165
1078
case SYNC_MEM_POOL:
1166
1079
case SYNC_MEM_HASH:
1167
1080
case SYNC_RECV:
1168
1081
case SYNC_WORK_QUEUE:
1170
case SYNC_LOG_FLUSH_ORDER:
1171
1083
case SYNC_THR_LOCAL:
1172
1084
case SYNC_ANY_LATCH:
1085
case SYNC_TRX_SYS_HEADER:
1173
1086
case SYNC_FILE_FORMAT_TAG:
1174
1087
case SYNC_DOUBLEWRITE:
1175
1089
case SYNC_SEARCH_SYS:
1176
1090
case SYNC_SEARCH_SYS_CONF:
1177
1091
case SYNC_TRX_LOCK_HEAP:
1186
1100
case SYNC_DICT_HEADER:
1187
1101
case SYNC_TRX_I_S_RWLOCK:
1188
1102
case SYNC_TRX_I_S_LAST_READ:
1189
if (!sync_thread_levels_g(array, level, TRUE)) {
1103
if (!sync_thread_levels_g(array, level)) {
1190
1104
fprintf(stderr,
1191
1105
"InnoDB: sync_thread_levels_g(array, %lu)"
1192
1106
" does not hold!\n", level);
1196
case SYNC_BUF_FLUSH_LIST:
1198
/* We can have multiple mutexes of this type therefore we
1199
can only check whether the greater than condition holds. */
1200
if (!sync_thread_levels_g(array, level-1, TRUE)) {
1202
"InnoDB: sync_thread_levels_g(array, %lu)"
1203
" does not hold!\n", level-1);
1208
1110
case SYNC_BUF_BLOCK:
1209
1111
/* Either the thread must own the buffer pool mutex
1210
1112
(buf_pool_mutex), or it is allowed to latch only ONE
1211
1113
buffer block (block->mutex or buf_pool_zip_mutex). */
1212
if (!sync_thread_levels_g(array, level, FALSE)) {
1213
ut_a(sync_thread_levels_g(array, level - 1, TRUE));
1114
if (!sync_thread_levels_g(array, level)) {
1115
ut_a(sync_thread_levels_g(array, level - 1));
1214
1116
ut_a(sync_thread_levels_contain(array, SYNC_BUF_POOL));
1217
1119
case SYNC_REC_LOCK:
1218
if (sync_thread_levels_contain(array, SYNC_KERNEL)) {
1219
ut_a(sync_thread_levels_g(array, SYNC_REC_LOCK - 1,
1222
ut_a(sync_thread_levels_g(array, SYNC_REC_LOCK, TRUE));
1120
ut_a((sync_thread_levels_contain(array, SYNC_KERNEL)
1121
&& sync_thread_levels_g(array, SYNC_REC_LOCK - 1))
1122
|| sync_thread_levels_g(array, SYNC_REC_LOCK));
1225
1124
case SYNC_IBUF_BITMAP:
1226
1125
/* Either the thread must own the master mutex to all
1227
1126
the bitmap pages, or it is allowed to latch only ONE
1228
1127
bitmap page. */
1229
if (sync_thread_levels_contain(array,
1230
SYNC_IBUF_BITMAP_MUTEX)) {
1231
ut_a(sync_thread_levels_g(array, SYNC_IBUF_BITMAP - 1,
1234
/* This is violated during trx_sys_create_rsegs()
1235
when creating additional rollback segments when
1236
upgrading in innobase_start_or_create_for_mysql(). */
1237
ut_a(srv_is_being_started
1238
|| sync_thread_levels_g(array, SYNC_IBUF_BITMAP,
1128
ut_a((sync_thread_levels_contain(array, SYNC_IBUF_BITMAP_MUTEX)
1129
&& sync_thread_levels_g(array, SYNC_IBUF_BITMAP - 1))
1130
|| sync_thread_levels_g(array, SYNC_IBUF_BITMAP));
1242
1132
case SYNC_FSP_PAGE:
1243
1133
ut_a(sync_thread_levels_contain(array, SYNC_FSP));
1246
1136
ut_a(sync_thread_levels_contain(array, SYNC_FSP)
1247
|| sync_thread_levels_g(array, SYNC_FSP, TRUE));
1137
|| sync_thread_levels_g(array, SYNC_FSP));
1249
1139
case SYNC_TRX_UNDO_PAGE:
1250
1140
ut_a(sync_thread_levels_contain(array, SYNC_TRX_UNDO)
1251
1141
|| sync_thread_levels_contain(array, SYNC_RSEG)
1252
1142
|| sync_thread_levels_contain(array, SYNC_PURGE_SYS)
1253
|| sync_thread_levels_g(array, SYNC_TRX_UNDO_PAGE, TRUE));
1143
|| sync_thread_levels_g(array, SYNC_TRX_UNDO_PAGE));
1255
1145
case SYNC_RSEG_HEADER:
1256
1146
ut_a(sync_thread_levels_contain(array, SYNC_RSEG));
1262
1152
case SYNC_TREE_NODE:
1263
1153
ut_a(sync_thread_levels_contain(array, SYNC_INDEX_TREE)
1264
1154
|| sync_thread_levels_contain(array, SYNC_DICT_OPERATION)
1265
|| sync_thread_levels_g(array, SYNC_TREE_NODE - 1, TRUE));
1155
|| sync_thread_levels_g(array, SYNC_TREE_NODE - 1));
1267
1157
case SYNC_TREE_NODE_NEW:
1268
1158
ut_a(sync_thread_levels_contain(array, SYNC_FSP_PAGE)
1269
1159
|| sync_thread_levels_contain(array, SYNC_IBUF_MUTEX));
1271
1161
case SYNC_INDEX_TREE:
1272
if (sync_thread_levels_contain(array, SYNC_IBUF_MUTEX)
1273
&& sync_thread_levels_contain(array, SYNC_FSP)) {
1274
ut_a(sync_thread_levels_g(array, SYNC_FSP_PAGE - 1,
1277
ut_a(sync_thread_levels_g(array, SYNC_TREE_NODE - 1,
1162
ut_a((sync_thread_levels_contain(array, SYNC_IBUF_MUTEX)
1163
&& sync_thread_levels_contain(array, SYNC_FSP)
1164
&& sync_thread_levels_g(array, SYNC_FSP_PAGE - 1))
1165
|| sync_thread_levels_g(array, SYNC_TREE_NODE - 1));
1281
1167
case SYNC_IBUF_MUTEX:
1282
ut_a(sync_thread_levels_g(array, SYNC_FSP_PAGE - 1, TRUE));
1168
ut_a(sync_thread_levels_g(array, SYNC_FSP_PAGE - 1));
1284
1170
case SYNC_IBUF_PESS_INSERT_MUTEX:
1285
ut_a(sync_thread_levels_g(array, SYNC_FSP - 1, TRUE));
1286
ut_a(!sync_thread_levels_contain(array, SYNC_IBUF_MUTEX));
1171
ut_a(sync_thread_levels_g(array, SYNC_FSP - 1)
1172
&& !sync_thread_levels_contain(array, SYNC_IBUF_MUTEX));
1288
1174
case SYNC_IBUF_HEADER:
1289
ut_a(sync_thread_levels_g(array, SYNC_FSP - 1, TRUE));
1290
ut_a(!sync_thread_levels_contain(array, SYNC_IBUF_MUTEX));
1291
ut_a(!sync_thread_levels_contain(array,
1292
SYNC_IBUF_PESS_INSERT_MUTEX));
1175
ut_a(sync_thread_levels_g(array, SYNC_FSP - 1)
1176
&& !sync_thread_levels_contain(array, SYNC_IBUF_MUTEX)
1177
&& !sync_thread_levels_contain(
1178
array, SYNC_IBUF_PESS_INSERT_MUTEX));
1294
1180
case SYNC_DICT:
1295
1181
#ifdef UNIV_DEBUG
1296
1182
ut_a(buf_debug_prints
1297
|| sync_thread_levels_g(array, SYNC_DICT, TRUE));
1183
|| sync_thread_levels_g(array, SYNC_DICT));
1298
1184
#else /* UNIV_DEBUG */
1299
ut_a(sync_thread_levels_g(array, SYNC_DICT, TRUE));
1185
ut_a(sync_thread_levels_g(array, SYNC_DICT));
1300
1186
#endif /* UNIV_DEBUG */
1432
1318
/* Init the mutex list and create the mutex to protect it. */
1434
1320
UT_LIST_INIT(mutex_list);
1435
mutex_create(mutex_list_mutex_key, &mutex_list_mutex,
1436
SYNC_NO_ORDER_CHECK);
1321
mutex_create(&mutex_list_mutex, SYNC_NO_ORDER_CHECK);
1437
1322
#ifdef UNIV_SYNC_DEBUG
1438
mutex_create(sync_thread_mutex_key, &sync_thread_mutex,
1439
SYNC_NO_ORDER_CHECK);
1323
mutex_create(&sync_thread_mutex, SYNC_NO_ORDER_CHECK);
1440
1324
#endif /* UNIV_SYNC_DEBUG */
1442
1326
/* Init the rw-lock list and create the mutex to protect it. */
1444
1328
UT_LIST_INIT(rw_lock_list);
1445
mutex_create(rw_lock_list_mutex_key, &rw_lock_list_mutex,
1446
SYNC_NO_ORDER_CHECK);
1329
mutex_create(&rw_lock_list_mutex, SYNC_NO_ORDER_CHECK);
1448
1331
#ifdef UNIV_SYNC_DEBUG
1449
mutex_create(rw_lock_debug_mutex_key, &rw_lock_debug_mutex,
1450
SYNC_NO_ORDER_CHECK);
1332
mutex_create(&rw_lock_debug_mutex, SYNC_NO_ORDER_CHECK);
1452
1334
rw_lock_debug_event = os_event_create(NULL);
1453
1335
rw_lock_debug_waiters = FALSE;