5656ulong tdc_size; /* *< Table definition cache threshold for LRU eviction. */
5757ulong tc_size; /* *< Table cache threshold for LRU eviction. */
5858uint32 tc_instances;
59- uint32 tc_active_instances= 1 ;
59+ static std::atomic< uint32_t > tc_active_instances ( 1 ) ;
6060static std::atomic<bool > tc_contention_warning_reported;
6161
6262/* * Data collections. */
@@ -163,7 +163,7 @@ struct Table_cache_instance
163163 overhead on TABLE object release. All other table cache mutex acquistions
164164 are considered out of hot path and are not instrumented either.
165165 */
166- void lock_and_check_contention (uint32 n_instances, uint32 instance)
166+ void lock_and_check_contention (uint32_t n_instances, uint32_t instance)
167167 {
168168 if (mysql_mutex_trylock (&LOCK_table_cache))
169169 {
@@ -172,11 +172,10 @@ struct Table_cache_instance
172172 {
173173 if (n_instances < tc_instances)
174174 {
175- if (my_atomic_cas32_weak_explicit ((int32*) &tc_active_instances,
176- (int32*) &n_instances,
177- (int32) n_instances + 1 ,
178- MY_MEMORY_ORDER_RELAXED,
179- MY_MEMORY_ORDER_RELAXED))
175+ if (tc_active_instances.
176+ compare_exchange_weak (n_instances, n_instances + 1 ,
177+ std::memory_order_relaxed,
178+ std::memory_order_relaxed))
180179 {
181180 sql_print_information (" Detected table cache mutex contention at instance %d: "
182181 " %d%% waits. Additional table cache instance "
@@ -354,8 +353,8 @@ void tc_purge(bool mark_flushed)
354353
355354void tc_add_table (THD *thd, TABLE *table)
356355{
357- uint32 i= thd-> thread_id % my_atomic_load32_explicit ((int32*) &tc_active_instances,
358- MY_MEMORY_ORDER_RELAXED );
356+ uint32_t i=
357+ thd-> thread_id % tc_active_instances. load (std::memory_order_relaxed );
359358 TABLE *LRU_table= 0 ;
360359 TDC_element *element= table->s ->tdc ;
361360
@@ -408,10 +407,8 @@ void tc_add_table(THD *thd, TABLE *table)
408407
409408TABLE *tc_acquire_table (THD *thd, TDC_element *element)
410409{
411- uint32 n_instances=
412- my_atomic_load32_explicit ((int32*) &tc_active_instances,
413- MY_MEMORY_ORDER_RELAXED);
414- uint32 i= thd->thread_id % n_instances;
410+ uint32_t n_instances= tc_active_instances.load (std::memory_order_relaxed);
411+ uint32_t i= thd->thread_id % n_instances;
415412 TABLE *table;
416413
417414 tc[i].lock_and_check_contention (n_instances, i);
@@ -1342,3 +1339,14 @@ int tdc_iterate(THD *thd, my_hash_walk_action action, void *argument,
13421339 }
13431340 return res;
13441341}
1342+
1343+
1344+ int show_tc_active_instances (THD *thd, SHOW_VAR *var, char *buff,
1345+ enum enum_var_type scope)
1346+ {
1347+ var->type = SHOW_UINT;
1348+ var->value = buff;
1349+ *(reinterpret_cast <uint32_t *>(buff))=
1350+ tc_active_instances.load (std::memory_order_relaxed);
1351+ return 0 ;
1352+ }
0 commit comments