MXS-1775 Move status management to MonitorInstance

This commit is contained in:
Johan Wikman
2018-05-16 14:00:23 +03:00
parent 1e084b78b1
commit 15e3a2887c
5 changed files with 12 additions and 12 deletions

View File

@ -40,7 +40,6 @@ protected:
static void main(void* pArg); static void main(void* pArg);
int m_status; /**< The current status of the monitor. */
MXS_MONITOR* m_monitor; /**< The generic monitor structure. */ MXS_MONITOR* m_monitor; /**< The generic monitor structure. */
int32_t m_shutdown; /**< Non-zero if the monitor should shut down. */ int32_t m_shutdown; /**< Non-zero if the monitor should shut down. */
std::string m_script; /**< Launchable script. */ std::string m_script; /**< Launchable script. */
@ -48,6 +47,7 @@ protected:
bool m_checked; /**< Whether server access has been checked. */ bool m_checked; /**< Whether server access has been checked. */
private: private:
int32_t m_status; /**< The current status of the monitor. */
THREAD m_thread; /**< The thread handle of the monitoring thread. */ THREAD m_thread; /**< The thread handle of the monitoring thread. */
}; };

View File

@ -2507,10 +2507,10 @@ namespace maxscale
{ {
MonitorInstance::MonitorInstance(MXS_MONITOR* pMonitor) MonitorInstance::MonitorInstance(MXS_MONITOR* pMonitor)
: m_status(0) : m_monitor(pMonitor)
, m_monitor(pMonitor)
, m_shutdown(0) , m_shutdown(0)
, m_events(0) , m_events(0)
, m_status(MXS_MONITOR_STOPPED)
, m_thread(0) , m_thread(0)
{ {
} }
@ -2522,10 +2522,14 @@ MonitorInstance::~MonitorInstance()
void MonitorInstance::stop() void MonitorInstance::stop()
{ {
// This is always called in single-thread context.
ss_dassert(m_thread); 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); atomic_store_int32(&m_shutdown, 1);
thread_wait(m_thread); thread_wait(m_thread);
m_thread = 0; m_thread = 0;
m_shutdown = 0; m_shutdown = 0;
} }
@ -2581,7 +2585,11 @@ void MonitorInstance::configure(const MXS_CONFIG_PARAMETER* pParams)
//static //static
void MonitorInstance::main(void* pArg) void MonitorInstance::main(void* pArg)
{ {
MonitorInstance* pThis = static_cast<MonitorInstance*>(pArg);
atomic_store_int32(&pThis->m_status, MXS_MONITOR_RUNNING);
static_cast<MonitorInstance*>(pArg)->main(); static_cast<MonitorInstance*>(pArg)->main();
atomic_store_int32(&pThis->m_status, MXS_MONITOR_STOPPED);
} }
} }

View File

@ -463,16 +463,14 @@ void GaleraMonitor::main()
MXS_ERROR("mysql_thread_init failed in monitor module. Exiting."); MXS_ERROR("mysql_thread_init failed in monitor module. Exiting.");
return; return;
} }
m_status = MXS_MONITOR_RUNNING;
load_server_journal(m_monitor, NULL); load_server_journal(m_monitor, NULL);
while (1) while (1)
{ {
if (m_shutdown) if (m_shutdown)
{ {
m_status = MXS_MONITOR_STOPPING;
mysql_thread_end(); mysql_thread_end();
m_status = MXS_MONITOR_STOPPED;
return; return;
} }

View File

@ -455,16 +455,13 @@ void MMMonitor::main()
return; return;
} }
m_status = MXS_MONITOR_RUNNING;
load_server_journal(mon, &m_master); load_server_journal(mon, &m_master);
while (1) while (1)
{ {
if (m_shutdown) if (m_shutdown)
{ {
m_status = MXS_MONITOR_STOPPING;
mysql_thread_end(); mysql_thread_end();
m_status = MXS_MONITOR_STOPPED;
return; return;
} }

View File

@ -255,16 +255,13 @@ void NDBCMonitor::main()
return; return;
} }
m_status = MXS_MONITOR_RUNNING;
load_server_journal(m_monitor, NULL); load_server_journal(m_monitor, NULL);
while (1) while (1)
{ {
if (m_shutdown) if (m_shutdown)
{ {
m_status = MXS_MONITOR_STOPPING;
mysql_thread_end(); mysql_thread_end();
m_status = MXS_MONITOR_STOPPED;
return; return;
} }