Skip to content

Commit

Permalink
MDEV-28920 Rescheduling of innodb_stats_func() missing
Browse files Browse the repository at this point in the history
Fixed tpool timer implementation on POSIX.
Prior to this patch, under some specific rare circumstances (concurrency
related), timer callback execution might be skipped.
  • Loading branch information
vaintroub committed Jun 23, 2022
1 parent 674842b commit 35f2cdc
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tpool/tpool_generic.cc
Expand Up @@ -345,22 +345,23 @@ class thread_pool_generic : public thread_pool
int m_period;
std::mutex m_mtx;
bool m_on;
std::atomic<bool> m_running;
std::atomic<int> m_running;

void run()
{
/*
In rare cases, multiple callbacks can be scheduled,
e.g with set_time(0,0) in a loop.
We do not allow parallel execution, as user is not prepared.
at the same time,. e.g with set_time(0,0) in a loop.
We do not allow parallel execution, since it is against the expectations.
*/
bool expected = false;
if (!m_running.compare_exchange_strong(expected, true))
if (m_running.fetch_add(1, std::memory_order_acquire) > 0)
return;

m_callback(m_data);
dbug_execute_after_task_callback();
m_running = false;
do
{
m_callback(m_data);
dbug_execute_after_task_callback();
}
while (m_running.fetch_sub(1, std::memory_order_release) != 1);

if (m_pool && m_period)
{
Expand Down

0 comments on commit 35f2cdc

Please sign in to comment.