44 #include "mysql/plugin.h"
50 #ifdef HAVE_ATOMIC_BUILTINS
52 UNIV_INTERN ulong srv_adaptive_max_sleep_delay = 150000;
70 #ifndef HAVE_ATOMIC_BUILTINS
94 static srv_conc_queue_t srv_conc_queue;
99 #if defined(UNIV_PFS_MUTEX)
101 UNIV_INTERN mysql_pfs_key_t srv_conc_mutex_key;
108 char pad[64 - (
sizeof(ulint) +
sizeof(lint))];
131 #ifndef HAVE_ATOMIC_BUILTINS
136 os_fast_mutex_init(srv_conc_mutex_key, &srv_conc_mutex);
141 mem_zalloc(OS_THREAD_MAX_N *
sizeof(*srv_conc_slots)));
143 for (i = 0; i < OS_THREAD_MAX_N; i++) {
158 #ifndef HAVE_ATOMIC_BUILTINS
159 os_fast_mutex_free(&srv_conc_mutex);
161 srv_conc_slots = NULL;
165 #ifdef HAVE_ATOMIC_BUILTINS
170 srv_enter_innodb_with_tickets(
193 srv_conc_enter_innodb_with_atomics(
199 ibool notified_mysql = FALSE;
210 n_active = os_atomic_increment_lint(
213 if (n_active <= srv_thread_concurrency) {
215 srv_enter_innodb_with_tickets(trx);
217 if (notified_mysql) {
219 (void) os_atomic_decrement_lint(
225 if (srv_adaptive_max_sleep_delay > 0) {
243 (void) os_atomic_decrement_lint(
247 if (!notified_mysql) {
248 (void) os_atomic_increment_lint(
260 notified_mysql = TRUE;
263 trx->
op_info =
"sleeping before entering InnoDB";
269 if (srv_adaptive_max_sleep_delay > 0
270 && sleep_in_us > srv_adaptive_max_sleep_delay) {
272 sleep_in_us = srv_adaptive_max_sleep_delay;
282 if (srv_adaptive_max_sleep_delay > 0 && n_sleeps > 1) {
292 srv_conc_exit_innodb_with_atomics(
299 (void) os_atomic_decrement_lint(&srv_conc.
n_active, 1);
306 srv_conc_exit_innodb_without_atomics(
312 os_fast_mutex_lock(&srv_conc_mutex);
321 if (srv_conc.
n_active < (lint) srv_thread_concurrency) {
342 os_fast_mutex_unlock(&srv_conc_mutex);
353 srv_conc_enter_innodb_without_atomics(
360 ibool has_slept = FALSE;
362 os_fast_mutex_lock(&srv_conc_mutex);
365 os_fast_mutex_unlock(&srv_conc_mutex);
367 fputs(
" InnoDB: Error: trying to declare trx"
368 " to enter InnoDB, but\n"
369 "InnoDB: it already is declared.\n", stderr);
377 if (srv_conc.
n_active < (lint) srv_thread_concurrency) {
383 os_fast_mutex_unlock(&srv_conc_mutex);
399 os_fast_mutex_unlock(&srv_conc_mutex);
401 trx->
op_info =
"sleeping before joining InnoDB queue";
414 os_fast_mutex_lock(&srv_conc_mutex);
423 for (i = 0; i < OS_THREAD_MAX_N; i++) {
424 slot = srv_conc_slots +
i;
432 if (i == OS_THREAD_MAX_N) {
440 os_fast_mutex_unlock(&srv_conc_mutex);
460 os_fast_mutex_unlock(&srv_conc_mutex);
466 #ifdef UNIV_SYNC_DEBUG
469 trx->
op_info =
"waiting in InnoDB queue";
473 os_event_wait(slot->
event);
478 os_fast_mutex_lock(&srv_conc_mutex);
492 os_fast_mutex_unlock(&srv_conc_mutex);
506 #ifdef UNIV_SYNC_DEBUG
510 #ifdef HAVE_ATOMIC_BUILTINS
511 srv_conc_enter_innodb_with_atomics(trx);
513 srv_conc_enter_innodb_without_atomics(trx);
527 #ifdef UNIV_SYNC_DEBUG
531 if (!srv_thread_concurrency) {
538 #ifdef HAVE_ATOMIC_BUILTINS
539 (void) os_atomic_increment_lint(&srv_conc.
n_active, 1);
541 os_fast_mutex_lock(&srv_conc_mutex);
543 os_fast_mutex_unlock(&srv_conc_mutex);
567 #ifdef HAVE_ATOMIC_BUILTINS
568 srv_conc_exit_innodb_with_atomics(trx);
570 srv_conc_exit_innodb_without_atomics(trx);
573 #ifdef UNIV_SYNC_DEBUG