Add RAII class for stopping monitors
This way the state is encapsulated in the object and the required changes are done in one place. This makes the code reusable across all functions making it easier to implement better monitor alteration code.
This commit is contained in:
parent
ac0a3d1d47
commit
906f0ed3cd
@ -760,21 +760,14 @@ bool do_alter_monitor(Monitor* monitor, const char* key, const char* value)
|
||||
|
||||
bool runtime_alter_monitor(Monitor* monitor, const char* key, const char* value)
|
||||
{
|
||||
// If the monitor is already stopped, don't stop/start it.
|
||||
bool was_running = (monitor->state() == MONITOR_STATE_RUNNING);
|
||||
if (was_running)
|
||||
{
|
||||
MonitorManager::stop_monitor(monitor);
|
||||
}
|
||||
MonitorStop stop(monitor);
|
||||
bool success = do_alter_monitor(monitor, key, value);
|
||||
|
||||
if (success)
|
||||
{
|
||||
MonitorManager::monitor_serialize(monitor);
|
||||
}
|
||||
if (was_running)
|
||||
{
|
||||
MonitorManager::start_monitor(monitor);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -178,3 +178,28 @@ public:
|
||||
*/
|
||||
static void debug_wait_one_tick();
|
||||
};
|
||||
|
||||
// RAII helper class for temprarily stopping monitors
|
||||
class MonitorStop
|
||||
{
|
||||
public:
|
||||
MonitorStop(mxs::Monitor* monitor)
|
||||
: m_monitor(monitor->state() == MONITOR_STATE_RUNNING ? monitor : nullptr)
|
||||
{
|
||||
if (m_monitor)
|
||||
{
|
||||
MonitorManager::stop_monitor(m_monitor);
|
||||
}
|
||||
}
|
||||
|
||||
~MonitorStop()
|
||||
{
|
||||
if (m_monitor)
|
||||
{
|
||||
MonitorManager::start_monitor(m_monitor);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
mxs::Monitor* m_monitor;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user