From 867eab37fc9106f6541b0ed14f9192ddde44c2e9 Mon Sep 17 00:00:00 2001 From: vraatikka Date: Fri, 26 Jul 2013 11:27:54 +0300 Subject: [PATCH] Monitors that run on separate thread call thread_wait in stopMonitor. Fixes problem with ordering of calls to mysql_library_end (in main) and mysql_thread_end (in monitor thr). --- modules/monitor/galera_mon.c | 5 +++-- modules/monitor/mysql_mon.c | 37 ++++++++++++++++++------------------ modules/monitor/mysqlmon.h | 13 +++++++------ 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/modules/monitor/galera_mon.c b/modules/monitor/galera_mon.c index 22b84d540..a996a3064 100644 --- a/modules/monitor/galera_mon.c +++ b/modules/monitor/galera_mon.c @@ -117,7 +117,7 @@ MYSQL_MONITOR *handle; handle->deaultPasswd = NULL; spinlock_init(&handle->lock); } - thread_start(monitorMain, handle); + handle->tid = thread_start(monitorMain, handle); return handle; } @@ -131,7 +131,8 @@ stopMonitor(void *arg) { MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; - handle->shutdown = 1; + handle->shutdown = 1; + thread_wait(handle->tid); } /** diff --git a/modules/monitor/mysql_mon.c b/modules/monitor/mysql_mon.c index c3b1a80a8..313e7e5a2 100644 --- a/modules/monitor/mysql_mon.c +++ b/modules/monitor/mysql_mon.c @@ -107,23 +107,23 @@ startMonitor(void *arg) { MYSQL_MONITOR *handle; - if (arg) - { - handle = arg; /* Must be a restart */ - handle->shutdown = 0; - } - else - { - if ((handle = (MYSQL_MONITOR *)malloc(sizeof(MYSQL_MONITOR))) == NULL) - return NULL; - handle->databases = NULL; - handle->shutdown = 0; - handle->defaultUser = NULL; - handle->defaultPasswd = NULL; - spinlock_init(&handle->lock); - } - thread_start(monitorMain, handle); - return handle; + if (arg) + { + handle = arg; /* Must be a restart */ + handle->shutdown = 0; + } + else + { + if ((handle = (MYSQL_MONITOR *)malloc(sizeof(MYSQL_MONITOR))) == NULL) + return NULL; + handle->databases = NULL; + handle->shutdown = 0; + handle->defaultUser = NULL; + handle->defaultPasswd = NULL; + spinlock_init(&handle->lock); + } + handle->tid = thread_start(monitorMain, handle); + return handle; } /** @@ -136,7 +136,8 @@ stopMonitor(void *arg) { MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; - handle->shutdown = 1; + handle->shutdown = 1; + thread_wait(handle->tid); } /** diff --git a/modules/monitor/mysqlmon.h b/modules/monitor/mysqlmon.h index 141d205c7..c2aacd21e 100644 --- a/modules/monitor/mysqlmon.h +++ b/modules/monitor/mysqlmon.h @@ -48,12 +48,13 @@ typedef struct monitor_servers { * The handle for an instance of a MySQL Monitor module */ typedef struct { - SPINLOCK lock; /**< The monitor spinlock */ - int shutdown; /**< Flag to shutdown the monitor thread */ - int status; /**< Monitor status */ - char *defaultUser; /**< Default username for monitoring */ - char *defaultPasswd; /**< Default password for monitoring */ - MONITOR_SERVERS *databases; /**< Linked list of servers to monitor */ + SPINLOCK lock; /**< The monitor spinlock */ + pthread_t tid; /**< id of monitor thread */ + int shutdown; /**< Flag to shutdown the monitor thread */ + int status; /**< Monitor status */ + char *defaultUser; /**< Default username for monitoring */ + char *defaultPasswd; /**< Default password for monitoring */ + MONITOR_SERVERS *databases; /**< Linked list of servers to monitor */ } MYSQL_MONITOR; #define MONITOR_RUNNING 1