Fix monitor repurposing

The monitor active state is now modified under the same lock. This should
make creation and destruction of monitors deterministic.
This commit is contained in:
Markus Mäkelä
2017-08-04 13:07:58 +03:00
parent 1743f4c1b7
commit 05d185fc02
3 changed files with 8 additions and 6 deletions

View File

@ -841,11 +841,11 @@ bool runtime_create_monitor(const char *name, const char *module)
if (monitor_find(name) == NULL) if (monitor_find(name) == NULL)
{ {
MXS_MONITOR *monitor = monitor_find_destroyed(name, module); MXS_MONITOR *monitor = monitor_repurpose_destroyed(name, module);
if (monitor) if (monitor)
{ {
monitor->active = true; MXS_DEBUG("Repurposed monitor '%s'", name);
} }
else if ((monitor = monitor_alloc(name, module)) == NULL) else if ((monitor = monitor_alloc(name, module)) == NULL)
{ {

View File

@ -50,7 +50,7 @@ void monitorStopAll();
void monitorStartAll(); void monitorStartAll();
MXS_MONITOR *monitor_find(const char *); MXS_MONITOR *monitor_find(const char *);
MXS_MONITOR* monitor_find_destroyed(const char* name, const char* module); MXS_MONITOR* monitor_repurpose_destroyed(const char* name, const char* module);
void monitorShow(DCB *, MXS_MONITOR *); void monitorShow(DCB *, MXS_MONITOR *);
void monitorShowAll(DCB *); void monitorShowAll(DCB *);

View File

@ -236,9 +236,9 @@ monitorStop(MXS_MONITOR *monitor)
void monitorDestroy(MXS_MONITOR* monitor) void monitorDestroy(MXS_MONITOR* monitor)
{ {
spinlock_acquire(&monitor->lock); spinlock_acquire(&monLock);
monitor->active = false; monitor->active = false;
spinlock_release(&monitor->lock); spinlock_release(&monLock);
} }
/** /**
@ -574,7 +574,7 @@ monitor_find(const char *name)
* @param name The name of the monitor * @param name The name of the monitor
* @return Pointer to the destroyed monitor or NULL if monitor is not found * @return Pointer to the destroyed monitor or NULL if monitor is not found
*/ */
MXS_MONITOR* monitor_find_destroyed(const char* name, const char* module) MXS_MONITOR* monitor_repurpose_destroyed(const char* name, const char* module)
{ {
MXS_MONITOR* rval = NULL; MXS_MONITOR* rval = NULL;
@ -584,6 +584,8 @@ MXS_MONITOR* monitor_find_destroyed(const char* name, const char* module)
{ {
if (strcmp(ptr->name, name) == 0 && strcmp(ptr->module_name, module) == 0) if (strcmp(ptr->name, name) == 0 && strcmp(ptr->module_name, module) == 0)
{ {
ss_dassert(!ptr->active);
ptr->active = true;
rval = ptr; rval = ptr;
} }
} }