Commit 35f2cdcb authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-28920 Rescheduling of innodb_stats_func() missing


Fixed tpool timer implementation on POSIX.
Prior to this patch, under some specific rare circumstances (concurrency
related), timer callback execution might be skipped.
parent 674842be
...@@ -345,22 +345,23 @@ class thread_pool_generic : public thread_pool ...@@ -345,22 +345,23 @@ class thread_pool_generic : public thread_pool
int m_period; int m_period;
std::mutex m_mtx; std::mutex m_mtx;
bool m_on; bool m_on;
std::atomic<bool> m_running; std::atomic<int> m_running;
void run() void run()
{ {
/* /*
In rare cases, multiple callbacks can be scheduled, In rare cases, multiple callbacks can be scheduled,
e.g with set_time(0,0) in a loop. at the same time,. e.g with set_time(0,0) in a loop.
We do not allow parallel execution, as user is not prepared. We do not allow parallel execution, since it is against the expectations.
*/ */
bool expected = false; if (m_running.fetch_add(1, std::memory_order_acquire) > 0)
if (!m_running.compare_exchange_strong(expected, true))
return; return;
do
{
m_callback(m_data); m_callback(m_data);
dbug_execute_after_task_callback(); dbug_execute_after_task_callback();
m_running = false; }
while (m_running.fetch_sub(1, std::memory_order_release) != 1);
if (m_pool && m_period) if (m_pool && m_period)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment