| 396 | */ |
| 397 | |
| 398 | TABLE *tc_acquire_table(THD *thd, TDC_element *element) |
| 399 | { |
| 400 | uint32_t n_instances= tc_active_instances.load(std::memory_order_relaxed); |
| 401 | uint32_t i= thd->thread_id % n_instances; |
| 402 | TABLE *table; |
| 403 | |
| 404 | tc[i].lock_and_check_contention(n_instances, i); |
| 405 | table= element->free_tables[i].list.pop_front(); |
| 406 | if (table) |
| 407 | { |
| 408 | DBUG_ASSERT(!table->in_use); |
| 409 | table->in_use= thd; |
| 410 | /* The ex-unused table must be fully functional. */ |
| 411 | DBUG_ASSERT(table->db_stat && table->file); |
| 412 | /* The children must be detached from the table. */ |
| 413 | DBUG_ASSERT(!table->file->extra(HA_EXTRA_IS_ATTACHED_CHILDREN)); |
| 414 | tc[i].free_tables.remove(table); |
| 415 | } |
| 416 | mysql_mutex_unlock(&tc[i].LOCK_table_cache); |
| 417 | return table; |
| 418 | } |
| 419 | |
| 420 | |
| 421 | /** |
no test coverage detected