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).
This commit is contained in:
vraatikka
2013-07-26 11:27:54 +03:00
parent 03e70ab78f
commit 867eab37fc
3 changed files with 29 additions and 26 deletions

View File

@ -117,7 +117,7 @@ MYSQL_MONITOR *handle;
handle->deaultPasswd = NULL; handle->deaultPasswd = NULL;
spinlock_init(&handle->lock); spinlock_init(&handle->lock);
} }
thread_start(monitorMain, handle); handle->tid = thread_start(monitorMain, handle);
return handle; return handle;
} }
@ -131,7 +131,8 @@ stopMonitor(void *arg)
{ {
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
handle->shutdown = 1; handle->shutdown = 1;
thread_wait(handle->tid);
} }
/** /**

View File

@ -107,23 +107,23 @@ startMonitor(void *arg)
{ {
MYSQL_MONITOR *handle; MYSQL_MONITOR *handle;
if (arg) if (arg)
{ {
handle = arg; /* Must be a restart */ handle = arg; /* Must be a restart */
handle->shutdown = 0; handle->shutdown = 0;
} }
else else
{ {
if ((handle = (MYSQL_MONITOR *)malloc(sizeof(MYSQL_MONITOR))) == NULL) if ((handle = (MYSQL_MONITOR *)malloc(sizeof(MYSQL_MONITOR))) == NULL)
return NULL; return NULL;
handle->databases = NULL; handle->databases = NULL;
handle->shutdown = 0; handle->shutdown = 0;
handle->defaultUser = NULL; handle->defaultUser = NULL;
handle->defaultPasswd = NULL; handle->defaultPasswd = NULL;
spinlock_init(&handle->lock); spinlock_init(&handle->lock);
} }
thread_start(monitorMain, handle); handle->tid = thread_start(monitorMain, handle);
return handle; return handle;
} }
/** /**
@ -136,7 +136,8 @@ stopMonitor(void *arg)
{ {
MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg; MYSQL_MONITOR *handle = (MYSQL_MONITOR *)arg;
handle->shutdown = 1; handle->shutdown = 1;
thread_wait(handle->tid);
} }
/** /**

View File

@ -48,12 +48,13 @@ typedef struct monitor_servers {
* The handle for an instance of a MySQL Monitor module * The handle for an instance of a MySQL Monitor module
*/ */
typedef struct { typedef struct {
SPINLOCK lock; /**< The monitor spinlock */ SPINLOCK lock; /**< The monitor spinlock */
int shutdown; /**< Flag to shutdown the monitor thread */ pthread_t tid; /**< id of monitor thread */
int status; /**< Monitor status */ int shutdown; /**< Flag to shutdown the monitor thread */
char *defaultUser; /**< Default username for monitoring */ int status; /**< Monitor status */
char *defaultPasswd; /**< Default password for monitoring */ char *defaultUser; /**< Default username for monitoring */
MONITOR_SERVERS *databases; /**< Linked list of servers to monitor */ char *defaultPasswd; /**< Default password for monitoring */
MONITOR_SERVERS *databases; /**< Linked list of servers to monitor */
} MYSQL_MONITOR; } MYSQL_MONITOR;
#define MONITOR_RUNNING 1 #define MONITOR_RUNNING 1