diff options
author | Vladislav Vaintroub <wlad@mariadb.com> | 2022-06-23 05:53:55 +0200 |
---|---|---|
committer | Vladislav Vaintroub <wlad@mariadb.com> | 2022-06-23 05:53:55 +0200 |
commit | 35f2cdcb99f4f8b39895070fde3f825329106361 (patch) | |
tree | 37cb728788b3818f75209b9377d62517dee71ff4 | |
parent | 674842bee0a564a2d94e99c4e1319a716aa10aa9 (diff) | |
download | mariadb-git-35f2cdcb99f4f8b39895070fde3f825329106361.tar.gz |
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.
-rw-r--r-- | tpool/tpool_generic.cc | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/tpool/tpool_generic.cc b/tpool/tpool_generic.cc index fb50b050dea..8dbd7c94d30 100644 --- a/tpool/tpool_generic.cc +++ b/tpool/tpool_generic.cc @@ -345,22 +345,23 @@ public: 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) { |