Remove unneded worker C-API

This commit is contained in:
Johan Wikman
2017-04-05 13:51:30 +03:00
parent 0e4e889c15
commit f1e99a475a
3 changed files with 31 additions and 128 deletions

View File

@ -76,7 +76,9 @@
#include "maxscale/poll.h"
#include "maxscale/service.h"
#include "maxscale/statistics.h"
#include "maxscale/worker.h"
#include "maxscale/worker.hh"
using maxscale::Worker;
#define STRING_BUFFER_SIZE 1024
#define PIDFD_CLOSED -1
@ -1284,7 +1286,7 @@ int main(int argc, char **argv)
void (*exitfunp[4])(void) = { mxs_log_finish, cleanup_process_datadir, write_footer, NULL };
MXS_CONFIG* cnf = NULL;
int numlocks = 0;
MXS_WORKER* worker;
Worker* worker;
*syslog_enabled = 1;
*maxlog_enabled = 1;
@ -1908,7 +1910,7 @@ int main(int argc, char **argv)
goto return_main;
}
mxs_worker_init();
Worker::init();
/* Init MaxScale modules */
if (!modules_process_init())
@ -1974,10 +1976,10 @@ int main(int argc, char **argv)
*/
for (i = 1; i < n_threads; i++)
{
MXS_WORKER* worker = mxs_worker_get(i);
worker = Worker::get(i);
ss_dassert(worker);
if (!mxs_worker_start(worker))
if (!worker->start())
{
const char* logerr = "Failed to start worker thread.";
print_log_n_stderr(true, true, logerr, logerr, 0);
@ -1999,9 +2001,9 @@ int main(int argc, char **argv)
/*<
* Run worker 0 in the main thread.
*/
worker = mxs_worker_get(0);
worker = Worker::get(0);
ss_dassert(worker);
mxs_worker_main(worker);
worker->run();
/*<
* Wait for the housekeeper to finish.
@ -2013,13 +2015,13 @@ int main(int argc, char **argv)
*/
for (i = 1; i < n_threads; i++)
{
MXS_WORKER *worker = mxs_worker_get(i);
worker = Worker::get(i);
ss_dassert(worker);
mxs_worker_join(worker);
worker->join();
}
mxs_worker_finish();
Worker::finish();
/*<
* Destroy the router and filter instances of all services.
@ -2089,7 +2091,7 @@ int maxscale_shutdown()
if (n == 0)
{
service_shutdown();
mxs_worker_shutdown_workers();
Worker::shutdown_all();
hkshutdown();
log_flush_shutdown();
}

View File

@ -16,71 +16,6 @@
MXS_BEGIN_DECLS
/**
* Initialize the worker mechanism.
*
* To be called once at process startup. This will cause as many workers
* to be created as the number of threads defined.
*/
void mxs_worker_init();
/**
* Finalize the worker mechanism.
*
* To be called once at process shutdown. This will cause all workers
* to be destroyed. When the function is called, no worker should be
* running anymore.
*/
void mxs_worker_finish();
/**
* Main function of worker.
*
* This worker will run the poll loop, until it is told to shut down.
*
* @param worker The worker.
*/
void mxs_worker_main(MXS_WORKER* worker);
/**
* Start worker in separate thread.
*
* This function will start a new thread, in which the `mxs_worker_main`
* function will be executed.
*
* @return True if the thread could be started, false otherwise.
*/
bool mxs_worker_start(MXS_WORKER* worker);
/**
* Waits for the worker to finish.
*
* @param worker The worker to wait for.
*/
void mxs_worker_join(MXS_WORKER* worker);
/**
* Initate shutdown of worker.
*
* @param worker The worker that should be shutdown.
*
* @attention A call to this function will only initiate the shutdowm,
* the worker will not have shut down when the function returns.
*
* @attention This function is signal safe.
*/
void mxs_worker_shutdown(MXS_WORKER* worker);
/**
* Initate shutdown of all workers.
*
* @attention A call to this function will only initiate the shutdowm,
* the workers will not have shut down when the function returns.
*
* @attention This function is signal safe.
*/
void mxs_worker_shutdown_workers();
/**
* Query whether worker should shutdown.
*

View File

@ -59,10 +59,6 @@ typedef struct worker_message
} WORKER_MESSAGE;
static MXS_WORKER* worker_create(int worker_id);
static void worker_free(MXS_WORKER* worker);
static uint32_t worker_poll_handler(MXS_POLL_DATA *data, int worker_id, uint32_t events);
static bool modules_thread_init();
static void modules_thread_finish();
@ -82,7 +78,7 @@ Worker::Worker(int id, int read_fd, int write_fd)
void Worker::init()
{
this_unit.n_workers = config_threadcount();
this_unit.ppWorkers = new (std::nothrow) Worker* (); // Zero initialized array
this_unit.ppWorkers = new (std::nothrow) Worker* [this_unit.n_workers] (); // Zero initialized array
if (!this_unit.ppWorkers)
{
@ -108,11 +104,6 @@ void Worker::init()
MXS_NOTICE("Workers created!");
}
void mxs_worker_init()
{
Worker::init();
}
void Worker::finish()
{
for (int i = 0; i < this_unit.n_workers; ++i)
@ -124,11 +115,6 @@ void Worker::finish()
}
}
void mxs_worker_finish()
{
Worker::finish();
}
Worker* Worker::get(int worker_id)
{
ss_dassert(worker_id < this_unit.n_workers);
@ -143,16 +129,16 @@ MXS_WORKER* mxs_worker_get(int worker_id)
MXS_WORKER* mxs_worker_get_current()
{
MXS_WORKER* worker = NULL;
Worker* pWorker = NULL;
int worker_id = this_thread.current_worker_id;
if (worker_id != WORKER_ABSENT_ID)
{
worker = mxs_worker_get(worker_id);
pWorker = Worker::get(worker_id);
}
return worker;
return pWorker;
}
int mxs_worker_get_current_id()
@ -163,7 +149,10 @@ int mxs_worker_get_current_id()
bool Worker::post_message(uint32_t msg_id, intptr_t arg1, intptr_t arg2)
{
// NOTE: No logging here, this function must be signal safe.
WORKER_MESSAGE message = { .id = msg_id, .arg1 = arg1, .arg2 = arg2 };
WORKER_MESSAGE message = {};
message.id = msg_id;
message.arg1 = arg1;
message.arg2 = arg2;
ssize_t n = write(m_write_fd, &message, sizeof(message));
@ -208,11 +197,6 @@ void Worker::run()
MXS_NOTICE("Worker %d has shut down.", m_id);
}
void mxs_worker_main(MXS_WORKER* pWorker)
{
return static_cast<Worker*>(pWorker)->run();
}
bool Worker::start()
{
m_started = true;
@ -225,11 +209,6 @@ bool Worker::start()
return m_started;
}
bool mxs_worker_start(MXS_WORKER* pWorker)
{
return static_cast<Worker*>(pWorker)->start();
}
void Worker::join()
{
if (m_started)
@ -241,11 +220,6 @@ void Worker::join()
}
}
void mxs_worker_join(MXS_WORKER* pWorker)
{
static_cast<Worker*>(pWorker)->join();
}
void Worker::shutdown()
{
// NOTE: No logging here, this function must be signal safe.
@ -259,11 +233,6 @@ void Worker::shutdown()
}
}
void mxs_worker_shutdown(MXS_WORKER* pWorker)
{
static_cast<Worker*>(pWorker)->shutdown();
}
void Worker::shutdown_all()
{
// NOTE: No logging here, this function must be signal safe.
@ -276,11 +245,6 @@ void Worker::shutdown_all()
}
}
void mxs_worker_shutdown_workers()
{
return Worker::shutdown_all();
}
/**
* Creates a worker instance.
* - Allocates the structure.
@ -325,11 +289,6 @@ Worker* Worker::create(int worker_id)
return pWorker;
}
/**
* Frees a worker instance.
*
* @param worker The worker instance to be freed.
*/
Worker::~Worker()
{
ss_dassert(!m_started);
@ -342,7 +301,6 @@ Worker::~Worker()
/**
* The worker message handler.
*
* @param worker The worker receiving the message.
* @param msg_id The message id.
* @param arg1 Message specific first argument.
* @param arg2 Message specific second argument.
@ -382,9 +340,8 @@ void Worker::handle_message(uint32_t msg_id, intptr_t arg1, intptr_t arg2)
}
/**
* Handler for poll events related to the read descriptor of the worker.
* Worker poll handler.
*
* @param data Pointer to the MXS_POLL_DATA member of the MXS_WORKER.
* @param thread_id Id of the thread; same as id of the relevant worker.
* @param events Epoll events.
*
@ -437,6 +394,15 @@ uint32_t Worker::poll(uint32_t events)
return rc;
}
/**
* Handler for poll events related to the read descriptor of the worker.
*
* @param pData The MXS_POLL_DATA of the worker in question.
* @param thread_id Id of the thread; same as id of the relevant worker.
* @param events Epoll events.
*
* @return What events the handler handled.
*/
//static
uint32_t Worker::poll_handler(MXS_POLL_DATA* pData, int thread_id, uint32_t events)
{