From bada05a88369051ee60623b006929dd728f704e8 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Sun, 12 Jan 2020 13:45:36 +0100 Subject: tpool - implement post-task callback (for Innodb debugging) --- storage/innobase/srv/srv0srv.cc | 10 ++++++++++ tpool/task.cc | 16 ++++++++++++++++ tpool/task_group.cc | 1 + tpool/tpool.h | 13 +++++++++++++ tpool/tpool_generic.cc | 2 +- tpool/tpool_win.cc | 1 + 6 files changed, 42 insertions(+), 1 deletion(-) diff --git a/storage/innobase/srv/srv0srv.cc b/storage/innobase/srv/srv0srv.cc index d7408222fd6..adc25bb4eeb 100644 --- a/storage/innobase/srv/srv0srv.cc +++ b/storage/innobase/srv/srv0srv.cc @@ -714,6 +714,13 @@ static void thread_pool_thread_end() } +#ifndef DBUG_OFF +static void dbug_after_task_callback() +{ + ut_ad(!sync_check_iterate(sync_check())); +} +#endif + void srv_thread_pool_init() { DBUG_ASSERT(!srv_thread_pool); @@ -725,6 +732,9 @@ void srv_thread_pool_init() #endif srv_thread_pool->set_thread_callbacks(thread_pool_thread_init, thread_pool_thread_end); +#ifndef DBUG_OFF + tpool::set_after_task_callback(dbug_after_task_callback); +#endif } diff --git a/tpool/task.cc b/tpool/task.cc index 6d456aa6f30..c8384321e50 100644 --- a/tpool/task.cc +++ b/tpool/task.cc @@ -21,6 +21,21 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 - 1301 USA*/ namespace tpool { + +#ifndef DBUG_OFF +static callback_func_np after_task_callback; +void set_after_task_callback(callback_func_np cb) +{ + after_task_callback= cb; +} + +void execute_after_task_callback() +{ + if (after_task_callback) + after_task_callback(); +} +#endif + task::task(callback_func func, void* arg, task_group* group) : m_func(func), m_arg(arg), m_group(group) {} @@ -35,6 +50,7 @@ namespace tpool { /* Execute directly. */ m_func(m_arg); + dbug_execute_after_task_callback(); release(); } } diff --git a/tpool/task_group.cc b/tpool/task_group.cc index b52fe7c0f67..97fbb0911c8 100644 --- a/tpool/task_group.cc +++ b/tpool/task_group.cc @@ -53,6 +53,7 @@ namespace tpool if (t) { t->m_func(t->m_arg); + dbug_execute_after_task_callback(); t->release(); } lk.lock(); diff --git a/tpool/tpool.h b/tpool/tpool.h index 472e59d5d9e..939ae919ff6 100644 --- a/tpool/tpool.h +++ b/tpool/tpool.h @@ -51,6 +51,7 @@ namespace tpool Task callback function */ typedef void (*callback_func)(void *); +typedef void (*callback_func_np)(void); class task; /** A class that can be used e.g. for @@ -174,6 +175,18 @@ class thread_pool; extern aio *create_simulated_aio(thread_pool *tp); +#ifndef DBUG_OFF +/* + This function is useful for debugging to make sure all mutexes are released + inside a task callback +*/ +void set_after_task_callback(callback_func_np cb); +void execute_after_task_callback(); +#define dbug_execute_after_task_callback() execute_after_task_callback() +#else +#define dbug_execute_after_task_callback() do{}while(0) +#endif + class thread_pool { protected: diff --git a/tpool/tpool_generic.cc b/tpool/tpool_generic.cc index fd5cba67e80..ec4f39b930b 100644 --- a/tpool/tpool_generic.cc +++ b/tpool/tpool_generic.cc @@ -293,7 +293,7 @@ public: return; m_callback(m_data); - + dbug_execute_after_task_callback(); m_running = false; if (m_pool && m_period) diff --git a/tpool/tpool_win.cc b/tpool/tpool_win.cc index 878d1af87c8..09fd49d9411 100644 --- a/tpool/tpool_win.cc +++ b/tpool/tpool_win.cc @@ -93,6 +93,7 @@ class thread_pool_win : public thread_pool return; } timer->m_func(timer->m_data); + dbug_execute_after_task_callback(); if (timer->m_period) timer->set_time(timer->m_period, timer->m_period); } -- cgit v1.2.1