Skip to content

Commit

Permalink
MDEV-17441 - InnoDB transition to C++11 atomics
Browse files Browse the repository at this point in the history
srv_conc_t.n_active and srv_conc_t.n_waiting transition to
Atomic_counter.
  • Loading branch information
Sergey Vojtovich committed Dec 27, 2018
1 parent d93653b commit b1c3e6c
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions storage/innobase/srv/srv0conc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ ulong srv_thread_concurrency = 0;

/** Variables tracking the active and waiting threads. */
struct srv_conc_t {
char pad[CACHE_LINE_SIZE - (sizeof(ulint) + sizeof(lint))];

/** Number of transactions that have declared_to_be_inside_innodb */
ulint n_active;
MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) Atomic_counter<ulint> n_active;

/** Number of OS threads waiting in the FIFO for permission to
enter InnoDB */
ulint n_waiting;
MY_ALIGNED(CPU_LEVEL1_DCACHE_LINESIZE) Atomic_counter<ulint> n_waiting;
};

/* Control variables for tracking concurrency. */
Expand Down Expand Up @@ -133,28 +131,22 @@ srv_conc_enter_innodb_with_atomics(

if (srv_thread_concurrency == 0) {
if (notified_mysql) {
my_atomic_addlint(&srv_conc.n_waiting,
ulint(-1));
srv_conc.n_waiting--;
thd_wait_end(trx->mysql_thd);
}

return;
}

if (srv_conc.n_active < srv_thread_concurrency) {
ulint n_active;

/* Check if there are any free tickets. */
n_active = my_atomic_addlint(
&srv_conc.n_active, 1) + 1;

if (n_active <= srv_thread_concurrency) {
if (srv_conc.n_active++ < srv_thread_concurrency) {

srv_enter_innodb_with_tickets(trx);

if (notified_mysql) {
my_atomic_addlint(&srv_conc.n_waiting,
ulint(-1));
srv_conc.n_waiting--;
thd_wait_end(trx->mysql_thd);
}

Expand All @@ -176,11 +168,11 @@ srv_conc_enter_innodb_with_atomics(
/* Since there were no free seats, we relinquish
the overbooked ticket. */

my_atomic_addlint(&srv_conc.n_active, ulint(-1));
srv_conc.n_active--;
}

if (!notified_mysql) {
my_atomic_addlint(&srv_conc.n_waiting, 1);
srv_conc.n_waiting++;

thd_wait_begin(trx->mysql_thd, THD_WAIT_USER_LOCK);

Expand Down Expand Up @@ -224,7 +216,7 @@ srv_conc_exit_innodb_with_atomics(
trx->n_tickets_to_enter_innodb = 0;
trx->declared_to_be_inside_innodb = FALSE;

my_atomic_addlint(&srv_conc.n_active, ulint(-1));
srv_conc.n_active--;
}

/*********************************************************************//**
Expand Down Expand Up @@ -258,7 +250,7 @@ srv_conc_force_enter_innodb(
return;
}

(void) my_atomic_addlint(&srv_conc.n_active, 1);
srv_conc.n_active++;

trx->n_tickets_to_enter_innodb = 1;
trx->declared_to_be_inside_innodb = TRUE;
Expand Down

0 comments on commit b1c3e6c

Please sign in to comment.