From 0b742977ddaad3c56d47ecf4da4843b79a24ac32 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 25 Jan 2016 20:41:30 +0200 Subject: [PATCH] Add specific thread main function. Earlier thread initialization was done in poll_waitevents(), which was somewhat confusing, since the main thread also calls into poll_waitevents(). Now there is a specific thread "main" function, which first performs thread specific initialization and then calls into poll_waitevents(). --- server/core/gateway.c | 24 +++++++++++++++++++++++- server/core/poll.c | 5 ----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/server/core/gateway.c b/server/core/gateway.c index 117fa30ed..9caf27241 100644 --- a/server/core/gateway.c +++ b/server/core/gateway.c @@ -982,6 +982,28 @@ static void usage(void) , progname); } + +/** + * The entry point of each worker thread. + * + * @param arg The thread argument. + */ +void worker_thread_main(void* arg) +{ + /** Init mysql thread context for use with a mysql handle and a parser */ + if (mysql_thread_init() == 0) + { + poll_waitevents(arg); + + /** Release mysql thread context */ + mysql_thread_end(); + } + else + { + MXS_ERROR("Could not perform thread initialization for MySQL. Exiting thread."); + } +} + /** * The main entry point into the gateway * @@ -1920,7 +1942,7 @@ int main(int argc, char **argv) */ for (thread_id = 0; thread_id < n_threads - 1; thread_id++) { - threads[thread_id] = thread_start(poll_waitevents, (void *)(thread_id + 1)); + threads[thread_id] = thread_start(worker_thread_main, (void *)(thread_id + 1)); } MXS_NOTICE("MaxScale started with %d server threads.", config_threadcount()); /** diff --git a/server/core/poll.c b/server/core/poll.c index f00e120de..b9504bee5 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -546,9 +546,6 @@ poll_waitevents(void *arg) thread_data[thread_id].state = THREAD_IDLE; } - /** Init mysql thread context for use with a mysql handle and a parser */ - mysql_thread_init(); - while (1) { if (pollStats.evq_pending == 0 && timeout_bias < 10) @@ -732,8 +729,6 @@ poll_waitevents(void *arg) thread_data[thread_id].state = THREAD_STOPPED; } bitmask_clear(&poll_mask, thread_id); - /** Release mysql thread context */ - mysql_thread_end(); return; } if (thread_data)