Synchronize the worker thread with the starting thread

This guarantees that the caller of the start function will know whether
the worker is running by looking at its state.

This will prevent multiple successive stop calls to a worker which
happened when the monitors were altered via the REST API.
This commit is contained in:
Markus Mäkelä
2018-08-17 16:21:22 +03:00
parent 9510a3ae1a
commit 208949f1cb
2 changed files with 24 additions and 10 deletions

View File

@ -22,6 +22,7 @@
#include <maxbase/semaphore.hh>
#include <maxscale/platform.h>
#include <maxscale/semaphore.hh>
#include <maxscale/session.h>
#include <maxscale/utils.hh>
#include <maxscale/worker.h>
@ -672,8 +673,10 @@ public:
* The worker will run the poll loop, until it is told to shut down.
*
* @attention This function will run in the calling thread.
*
* @param pSem Semaphore that is posted on once the thread has started
*/
void run();
void run(mxs::Semaphore* pSem = NULL);
/**
* Run worker in separate thread.
@ -1177,7 +1180,7 @@ private:
void handle_message(MessageQueue& queue, const MessageQueue::Message& msg); // override
static void thread_main(Worker* pThis);
static void thread_main(Worker* pThis, mxs::Semaphore* pSem);
void poll_waitevents();