| 380 | } |
| 381 | |
| 382 | void |
| 383 | dbcontext::lock_tables_if() |
| 384 | { |
| 385 | if (lock_failed) { |
| 386 | return; |
| 387 | } |
| 388 | if (for_write_flag && !user_level_lock_locked) { |
| 389 | if (user_lock->get_lock()) { |
| 390 | user_level_lock_locked = true; |
| 391 | } else { |
| 392 | lock_failed = true; |
| 393 | return; |
| 394 | } |
| 395 | } |
| 396 | if (lock == 0) { |
| 397 | const size_t num_max = table_vec.size(); |
| 398 | TABLE **const tables = DENA_ALLOCA_ALLOCATE(TABLE *, num_max + 1); |
| 399 | size_t num_open = 0; |
| 400 | for (size_t i = 0; i < num_max; ++i) { |
| 401 | if (table_vec[i].refcount > 0) { |
| 402 | tables[num_open++] = table_vec[i].table; |
| 403 | } |
| 404 | table_vec[i].modified = false; |
| 405 | } |
| 406 | #if MYSQL_VERSION_ID >= 50505 |
| 407 | lock = thd->lock = mysql_lock_tables(thd, &tables[0], num_open, 0); |
| 408 | #else |
| 409 | bool need_reopen= false; |
| 410 | lock = thd->lock = mysql_lock_tables(thd, &tables[0], num_open, |
| 411 | MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN, &need_reopen); |
| 412 | #endif |
| 413 | statistic_increment(lock_tables_count, &LOCK_status); |
| 414 | thd_proc_info(thd, &info_message_buf[0]); |
| 415 | DENA_VERBOSE(100, fprintf(stderr, "HNDSOCK lock tables %p %p %zu %zu\n", |
| 416 | thd, lock, num_max, num_open)); |
| 417 | if (lock == 0) { |
| 418 | lock_failed = true; |
| 419 | DENA_VERBOSE(10, fprintf(stderr, "HNDSOCK failed to lock tables %p\n", |
| 420 | thd)); |
| 421 | } |
| 422 | if (for_write_flag) { |
| 423 | #if MYSQL_VERSION_ID >= 50505 |
| 424 | thd->set_current_stmt_binlog_format_row(); |
| 425 | #else |
| 426 | thd->current_stmt_binlog_row_based = 1; |
| 427 | #endif |
| 428 | } |
| 429 | DENA_ALLOCA_FREE(tables); |
| 430 | } |
| 431 | DBG_LOCK(fprintf(stderr, "HNDSOCK tblnum=%d\n", (int)tblnum)); |
| 432 | } |
| 433 | |
| 434 | void |
| 435 | dbcontext::unlock_tables_if() |