diff --git a/include/maxscale/monitor.hh b/include/maxscale/monitor.hh index 8e259cfad..4c47254b3 100644 --- a/include/maxscale/monitor.hh +++ b/include/maxscale/monitor.hh @@ -40,7 +40,6 @@ protected: static void main(void* pArg); - int m_status; /**< The current status of the monitor. */ MXS_MONITOR* m_monitor; /**< The generic monitor structure. */ int32_t m_shutdown; /**< Non-zero if the monitor should shut down. */ std::string m_script; /**< Launchable script. */ @@ -48,6 +47,7 @@ protected: bool m_checked; /**< Whether server access has been checked. */ private: + int32_t m_status; /**< The current status of the monitor. */ THREAD m_thread; /**< The thread handle of the monitoring thread. */ }; diff --git a/server/core/monitor.cc b/server/core/monitor.cc index 5333f8982..8b99951c3 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -2507,10 +2507,10 @@ namespace maxscale { MonitorInstance::MonitorInstance(MXS_MONITOR* pMonitor) - : m_status(0) - , m_monitor(pMonitor) + : m_monitor(pMonitor) , m_shutdown(0) , m_events(0) + , m_status(MXS_MONITOR_STOPPED) , m_thread(0) { } @@ -2522,10 +2522,14 @@ MonitorInstance::~MonitorInstance() void MonitorInstance::stop() { + // This is always called in single-thread context. ss_dassert(m_thread); + ss_dassert(m_status == MXS_MONITOR_RUNNING); + atomic_store_int32(&m_status, MXS_MONITOR_STOPPING); atomic_store_int32(&m_shutdown, 1); thread_wait(m_thread); + m_thread = 0; m_shutdown = 0; } @@ -2581,7 +2585,11 @@ void MonitorInstance::configure(const MXS_CONFIG_PARAMETER* pParams) //static void MonitorInstance::main(void* pArg) { + MonitorInstance* pThis = static_cast(pArg); + + atomic_store_int32(&pThis->m_status, MXS_MONITOR_RUNNING); static_cast(pArg)->main(); + atomic_store_int32(&pThis->m_status, MXS_MONITOR_STOPPED); } } diff --git a/server/modules/monitor/galeramon/galeramon.cc b/server/modules/monitor/galeramon/galeramon.cc index 479b334f8..c6f8d5dd7 100644 --- a/server/modules/monitor/galeramon/galeramon.cc +++ b/server/modules/monitor/galeramon/galeramon.cc @@ -463,16 +463,14 @@ void GaleraMonitor::main() MXS_ERROR("mysql_thread_init failed in monitor module. Exiting."); return; } - m_status = MXS_MONITOR_RUNNING; + load_server_journal(m_monitor, NULL); while (1) { if (m_shutdown) { - m_status = MXS_MONITOR_STOPPING; mysql_thread_end(); - m_status = MXS_MONITOR_STOPPED; return; } diff --git a/server/modules/monitor/mmmon/mmmon.cc b/server/modules/monitor/mmmon/mmmon.cc index 490498700..caeb0b57b 100644 --- a/server/modules/monitor/mmmon/mmmon.cc +++ b/server/modules/monitor/mmmon/mmmon.cc @@ -455,16 +455,13 @@ void MMMonitor::main() return; } - m_status = MXS_MONITOR_RUNNING; load_server_journal(mon, &m_master); while (1) { if (m_shutdown) { - m_status = MXS_MONITOR_STOPPING; mysql_thread_end(); - m_status = MXS_MONITOR_STOPPED; return; } diff --git a/server/modules/monitor/ndbclustermon/ndbclustermon.cc b/server/modules/monitor/ndbclustermon/ndbclustermon.cc index eeed2f4d8..c855756a8 100644 --- a/server/modules/monitor/ndbclustermon/ndbclustermon.cc +++ b/server/modules/monitor/ndbclustermon/ndbclustermon.cc @@ -255,16 +255,13 @@ void NDBCMonitor::main() return; } - m_status = MXS_MONITOR_RUNNING; load_server_journal(m_monitor, NULL); while (1) { if (m_shutdown) { - m_status = MXS_MONITOR_STOPPING; mysql_thread_end(); - m_status = MXS_MONITOR_STOPPED; return; }