From 1304fd614766902eb1aa7a8094b0ccb0e483d87c Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 16 May 2018 11:09:11 +0300 Subject: [PATCH] MXS-1775 Move thread main function to maxscale::MonitorInstance --- include/maxscale/monitor.hh | 4 ++++ server/core/monitor.cc | 6 ++++++ server/modules/monitor/auroramon/auroramon.cc | 8 +------- server/modules/monitor/auroramon/auroramon.hh | 1 - server/modules/monitor/galeramon/galeramon.cc | 8 +------- server/modules/monitor/galeramon/galeramon.hh | 1 - server/modules/monitor/grmon/grmon.cc | 8 +------- server/modules/monitor/grmon/grmon.hh | 1 - server/modules/monitor/mmmon/mmmon.cc | 7 +------ server/modules/monitor/mmmon/mmmon.hh | 1 - server/modules/monitor/ndbclustermon/ndbclustermon.cc | 8 +------- server/modules/monitor/ndbclustermon/ndbclustermon.hh | 1 - 12 files changed, 15 insertions(+), 39 deletions(-) diff --git a/include/maxscale/monitor.hh b/include/maxscale/monitor.hh index 806d50707..bf26847bd 100644 --- a/include/maxscale/monitor.hh +++ b/include/maxscale/monitor.hh @@ -30,6 +30,10 @@ public: protected: MonitorInstance(MXS_MONITOR* pMonitor); + virtual void main() = 0; + + static void main(void* pArg); + int m_status; /**< The current status of the monitor. */ THREAD m_thread; /**< The thread handle of the monitoring thread. */ MXS_MONITOR* m_monitor; /**< The generic monitor structure. */ diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 2582fb524..02bdf0746 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -2522,4 +2522,10 @@ MonitorInstance::~MonitorInstance() ss_dassert(!m_script); } +//static +void MonitorInstance::main(void* pArg) +{ + static_cast(pArg)->main(); +} + } diff --git a/server/modules/monitor/auroramon/auroramon.cc b/server/modules/monitor/auroramon/auroramon.cc index 44c428c75..126a6455c 100644 --- a/server/modules/monitor/auroramon/auroramon.cc +++ b/server/modules/monitor/auroramon/auroramon.cc @@ -119,12 +119,6 @@ void update_server_status(MXS_MONITOR *monitor, MXS_MONITORED_SERVER *database) * * @param arg The MONITOR object for this monitor */ -//static -void AuroraMonitor::main(void* data) -{ - static_cast(data)->main(); -} - void AuroraMonitor::main() { if (mysql_thread_init()) @@ -210,7 +204,7 @@ bool AuroraMonitor::start(const MXS_CONFIG_PARAMETER *params) m_script = config_copy_string(params, "script"); m_events = config_get_enum(params, "events", mxs_monitor_event_enum_values); - if (thread_start(&m_thread, &AuroraMonitor::main, this, 0) == NULL) + if (thread_start(&m_thread, &maxscale::MonitorInstance::main, this, 0) == NULL) { MXS_ERROR("Failed to start monitor thread for monitor '%s'.", m_monitor->name); MXS_FREE(m_script); diff --git a/server/modules/monitor/auroramon/auroramon.hh b/server/modules/monitor/auroramon/auroramon.hh index b8fd808b0..39d6bf405 100644 --- a/server/modules/monitor/auroramon/auroramon.hh +++ b/server/modules/monitor/auroramon/auroramon.hh @@ -38,5 +38,4 @@ private: ~AuroraMonitor(); void main(); - static void main(void* data); }; diff --git a/server/modules/monitor/galeramon/galeramon.cc b/server/modules/monitor/galeramon/galeramon.cc index d96eccf07..5e37ffc79 100644 --- a/server/modules/monitor/galeramon/galeramon.cc +++ b/server/modules/monitor/galeramon/galeramon.cc @@ -189,7 +189,7 @@ bool GaleraMonitor::start(const MXS_CONFIG_PARAMETER *params) /* Reset all data in the hashtable */ reset_cluster_info(); - if (thread_start(&m_thread, &GaleraMonitor::main, this, 0) == NULL) + if (thread_start(&m_thread, &maxscale::MonitorInstance::main, this, 0) == NULL) { MXS_ERROR("Failed to start monitor thread for monitor '%s'.", m_monitor->name); } @@ -503,12 +503,6 @@ void GaleraMonitor::monitorDatabase(MXS_MONITORED_SERVER *database) * * @param arg The handle of the monitor */ -//static -void GaleraMonitor::main(void* arg) -{ - return static_cast(arg)->main(); -} - void GaleraMonitor::main() { MXS_MONITORED_SERVER *ptr; diff --git a/server/modules/monitor/galeramon/galeramon.hh b/server/modules/monitor/galeramon/galeramon.hh index 252e47b59..87adc55cf 100644 --- a/server/modules/monitor/galeramon/galeramon.hh +++ b/server/modules/monitor/galeramon/galeramon.hh @@ -93,5 +93,4 @@ private: void update_sst_donor_nodes(int is_cluster); void main(); - static void main(void* data); }; diff --git a/server/modules/monitor/grmon/grmon.cc b/server/modules/monitor/grmon/grmon.cc index ef228f4e9..4a54acdf6 100644 --- a/server/modules/monitor/grmon/grmon.cc +++ b/server/modules/monitor/grmon/grmon.cc @@ -57,7 +57,7 @@ bool GRMon::start(const MXS_CONFIG_PARAMETER* params) m_events = config_get_enum(params, "events", mxs_monitor_event_enum_values); m_thread = 0; - if (thread_start(&m_thread, GRMon::main, this, 0) != NULL) + if (thread_start(&m_thread, &maxscale::MonitorInstance::main, this, 0) != NULL) { started = true; } @@ -65,12 +65,6 @@ bool GRMon::start(const MXS_CONFIG_PARAMETER* params) return started; } -void GRMon::main(void* data) -{ - GRMon* mon = (GRMon*)data; - mon->main(); -} - void GRMon::stop() { ss_dassert(m_thread); diff --git a/server/modules/monitor/grmon/grmon.hh b/server/modules/monitor/grmon/grmon.hh index 997165431..d464d52b7 100644 --- a/server/modules/monitor/grmon/grmon.hh +++ b/server/modules/monitor/grmon/grmon.hh @@ -41,5 +41,4 @@ private: ~GRMon(); void main(); - static void main(void* data); }; diff --git a/server/modules/monitor/mmmon/mmmon.cc b/server/modules/monitor/mmmon/mmmon.cc index eb71336de..d87e5f5da 100644 --- a/server/modules/monitor/mmmon/mmmon.cc +++ b/server/modules/monitor/mmmon/mmmon.cc @@ -139,7 +139,7 @@ bool MMMonitor::start(const MXS_CONFIG_PARAMETER *params) m_script = config_copy_string(params, "script"); m_events = config_get_enum(params, "events", mxs_monitor_event_enum_values); - if (thread_start(&m_thread, MMMonitor::main, this, 0) == NULL) + if (thread_start(&m_thread, &maxscale::MonitorInstance::main, this, 0) == NULL) { MXS_ERROR("Failed to start monitor thread for monitor '%s'.", m_monitor->name); MXS_FREE(m_script); @@ -492,11 +492,6 @@ monitorDatabase(MXS_MONITOR* mon, MXS_MONITORED_SERVER *database) * * @param arg The handle of the monitor */ -void MMMonitor::main(void* arg) -{ - static_cast(arg)->main(); -} - void MMMonitor::main() { MXS_MONITOR* mon = m_monitor; diff --git a/server/modules/monitor/mmmon/mmmon.hh b/server/modules/monitor/mmmon/mmmon.hh index b1f22e71c..9b49e6bd5 100644 --- a/server/modules/monitor/mmmon/mmmon.hh +++ b/server/modules/monitor/mmmon/mmmon.hh @@ -44,5 +44,4 @@ private: MXS_MONITORED_SERVER *get_current_master(); void main(); - static void main(void* data); }; diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.cc b/server/modules/monitor/ndbclustermon/ndbclustermon.cc index 87ba61500..3775ee44d 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.cc +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.cc @@ -122,7 +122,7 @@ bool NDBCMonitor::start(const MXS_CONFIG_PARAMETER *params) m_script = config_copy_string(params, "script"); m_events = config_get_enum(params, "events", mxs_monitor_event_enum_values); - if (thread_start(&m_thread, &NDBCMonitor::main, this, 0) == NULL) + if (thread_start(&m_thread, &maxscale::MonitorInstance::main, this, 0) == NULL) { MXS_ERROR("Failed to start monitor thread for monitor '%s'.", m_monitor->name); MXS_FREE(m_script); @@ -298,12 +298,6 @@ monitorDatabase(MXS_MONITORED_SERVER *database, char *defaultUser, char *default * * @param arg The handle of the monitor */ -//static -void NDBCMonitor::main(void* arg) -{ - static_cast(arg)->main(); -} - void NDBCMonitor::main() { MXS_MONITORED_SERVER *ptr; diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.hh b/server/modules/monitor/ndbclustermon/ndbclustermon.hh index 61fee95ab..434440f4f 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.hh +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.hh @@ -41,5 +41,4 @@ private: ~NDBCMonitor(); void main(); - static void main(void* data); };