summaryrefslogtreecommitdiff
path: root/tpool
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2020-01-12 13:45:36 +0100
committerVladislav Vaintroub <wlad@mariadb.com>2020-01-12 19:08:02 +0100
commitbada05a88369051ee60623b006929dd728f704e8 (patch)
tree4762067c46633a33f8e39a259ffee67f13fee178 /tpool
parent90002480e9fa8708987179116a2b180282628b06 (diff)
downloadmariadb-git-bada05a88369051ee60623b006929dd728f704e8.tar.gz
tpool - implement post-task callback (for Innodb debugging)
Diffstat (limited to 'tpool')
-rw-r--r--tpool/task.cc16
-rw-r--r--tpool/task_group.cc1
-rw-r--r--tpool/tpool.h13
-rw-r--r--tpool/tpool_generic.cc2
-rw-r--r--tpool/tpool_win.cc1
5 files changed, 32 insertions, 1 deletions
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);
}