Add shutdown support

The shutdown is now performed so that a shutdown message is
sent to all workers. When the workers receive that message, they
turn on a shutdown flag, which subsequently is checked in the poll
loop.
This commit is contained in:
Johan Wikman
2017-02-16 13:54:18 +02:00
parent ab37333ce5
commit 5138032fe5
7 changed files with 99 additions and 31 deletions

View File

@ -20,12 +20,14 @@ MXS_BEGIN_DECLS
typedef struct mxs_worker
{
MXS_POLL_DATA poll; /*< The poll data used by the polling mechanism. */
int id; /*< The id of the worker. */
int read_fd; /*< The file descriptor the worked reads from. */
int write_fd; /*< The file descriptor used for sending data to the worker. */
THREAD thread; /*< The thread handle of the worker. */
bool started; /*< Whether the thread has been started or not. */
MXS_POLL_DATA poll; /*< The poll data used by the polling mechanism. */
int id; /*< The id of the worker. */
int read_fd; /*< The file descriptor the worked reads from. */
int write_fd; /*< The file descriptor used for sending data to the worker. */
THREAD thread; /*< The thread handle of the worker. */
bool started; /*< Whether the thread has been started or not. */
bool should_shutdown; /*< Whether shutdown should be performed. */
bool shutdown_initiated; /*< Whether shutdown has been initated. */
} MXS_WORKER;
enum mxs_worker_msg_id
@ -37,7 +39,15 @@ enum mxs_worker_msg_id
* arg2: NULL or pointer to dynamically allocated NULL-terminated string,
* to be freed by worker.
*/
MXS_WORKER_MSG_PING
MXS_WORKER_MSG_PING,
/**
* Shutdown message.
*
* arg1: 0
* arg2: NULL
*/
MXS_WORKER_MSG_SHUTDOWN
};
/**
@ -75,6 +85,8 @@ static inline int mxs_worker_id(MXS_WORKER* worker)
*
* @attention The return value tells *only* whether the message could be sent,
* *not* that it has reached the worker.
*
* @attention This function is signal safe.
*/
bool mxs_worker_post_message(MXS_WORKER* worker, int msg_id, int64_t arg1, void* arg2);