From e9758ebaf1324d9a0d0bbbcfc115fc351e9e71d9 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Thu, 9 Aug 2018 15:10:31 +0300 Subject: [PATCH] MXS-2002 Rename Worker::post() to Worker::execute() The main point is that tasks/functions are executed, not that they are posted. --- include/maxscale/worker.hh | 29 +++++++++---------- server/core/dcb.cc | 4 +-- server/core/resource.cc | 2 +- server/core/routingworker.cc | 8 ++--- server/core/session.cc | 4 +-- server/core/worker.cc | 10 +++---- .../modules/monitor/mariadbmon/mariadbmon.cc | 2 +- .../modules/routing/avrorouter/avro_main.cc | 2 +- 8 files changed, 30 insertions(+), 31 deletions(-) diff --git a/include/maxscale/worker.hh b/include/maxscale/worker.hh index ab4bbb933..9ca635c01 100644 --- a/include/maxscale/worker.hh +++ b/include/maxscale/worker.hh @@ -706,13 +706,14 @@ public: } /** - * Posts a task to a worker for execution. + * Executes a task on the worker thread. * * @param pTask The task to be executed. * @param pSem If non-NULL, will be posted once the task's `execute` return. * @param mode Execution mode * - * @return True if the task could be posted (i.e. not executed), false otherwise. + * @return True if the task could be posted to the worker (i.e. not executed yet), + false otherwise. * * @attention The instance must remain valid for as long as it takes for the * task to be transferred to the worker and its `execute` function @@ -730,27 +731,27 @@ public: * MyResult& result = task.result(); * @endcode */ - bool post(Task* pTask, Semaphore* pSem, enum execute_mode_t mode); + bool execute(Task* pTask, Semaphore* pSem, enum execute_mode_t mode); - bool post(Task* pTask, enum execute_mode_t mode) + bool execute(Task* pTask, enum execute_mode_t mode) { - return post(pTask, NULL, mode); + return execute(pTask, NULL, mode); } /** - * Posts a task to a worker for execution. + * Executes a task on the worker thread. * * @param pTask The task to be executed. * @param mode Execution mode * - * @return True if the task could be posted (i.e. not executed), false otherwise. + * @return True if the task could be posted (i.e. not executed yet), false otherwise. * * @attention Once the task has been executed, it will be deleted. */ - bool post(std::unique_ptr sTask, enum execute_mode_t mode); + bool execute(std::unique_ptr sTask, enum execute_mode_t mode); /** - * Execute a funcion in a worker + * Execute a function on the worker thread. * * @param func The function to call * @param pSem If non-NULL, will be posted once the task's `execute` return. @@ -758,18 +759,16 @@ public: * * @return True, if task was posted to the worker */ - bool post(GenericFunction func, Semaphore* pSem, enum execute_mode_t mode); + bool execute(GenericFunction func, Semaphore* pSem, enum execute_mode_t mode); /** - * Execute function on worker - * - * This is a convenience wrapper of `post` with automatic waiting on the - * semaphore. + * Execute function on worker thread and return only when it has + * been executed. * * @param func Function to execute * @param mode Execution mode * - * @return True if function was executed on the worker + * @return True if function was executed on the worker. */ bool call(GenericFunction func, enum execute_mode_t mode); diff --git a/server/core/dcb.cc b/server/core/dcb.cc index 184ca16d2..46887fb25 100644 --- a/server/core/dcb.cc +++ b/server/core/dcb.cc @@ -3309,7 +3309,7 @@ static void poll_add_event_to_dcb(DCB* dcb, GWBUF* buf, uint32_t ev) if (task) { RoutingWorker* worker = static_cast(dcb->poll.owner); - worker->post(std::unique_ptr(task), mxs::Worker::EXECUTE_QUEUED); + worker->execute(std::unique_ptr(task), mxs::Worker::EXECUTE_QUEUED); } else { @@ -3523,7 +3523,7 @@ static bool dcb_add_to_worker(Worker* worker, DCB* dcb, uint32_t events) Worker* worker = static_cast(dcb->poll.owner); ss_dassert(worker); - if (worker->post(std::unique_ptr(task), mxs::Worker::EXECUTE_QUEUED)) + if (worker->execute(std::unique_ptr(task), mxs::Worker::EXECUTE_QUEUED)) { rv = true; } diff --git a/server/core/resource.cc b/server/core/resource.cc index 8df96f48b..a357edcf5 100644 --- a/server/core/resource.cc +++ b/server/core/resource.cc @@ -1280,7 +1280,7 @@ HttpResponse resource_handle_request(const HttpRequest& request) mxs::Semaphore sem; ResourceTask task(request); - worker->post(&task, &sem, mxs::Worker::EXECUTE_AUTO); + worker->execute(&task, &sem, mxs::Worker::EXECUTE_AUTO); sem.wait(); return task.result(); diff --git a/server/core/routingworker.cc b/server/core/routingworker.cc index 988f8898a..780832e6b 100644 --- a/server/core/routingworker.cc +++ b/server/core/routingworker.cc @@ -604,7 +604,7 @@ size_t RoutingWorker::broadcast(Task* pTask, Semaphore* pSem) Worker* pWorker = this_unit.ppWorkers[i]; ss_dassert(pWorker); - if (pWorker->post(pTask, pSem, EXECUTE_AUTO)) + if (pWorker->execute(pTask, pSem, EXECUTE_AUTO)) { ++n; } @@ -650,7 +650,7 @@ size_t RoutingWorker::execute_serially(Task& task) RoutingWorker* pWorker = this_unit.ppWorkers[i]; ss_dassert(pWorker); - if (pWorker->post(&task, &sem, EXECUTE_AUTO)) + if (pWorker->execute(&task, &sem, EXECUTE_AUTO)) { sem.wait(); ++n; @@ -894,7 +894,7 @@ bool RoutingWorker::get_qc_stats(int id, QC_CACHE_STATS* pStats) { Semaphore sem; Task task(pStats); - pWorker->post(&task, &sem, EXECUTE_AUTO); + pWorker->execute(&task, &sem, EXECUTE_AUTO); sem.wait(); } @@ -1205,7 +1205,7 @@ json_t* mxs_rworker_to_json(const char* zHost, int id) WorkerInfoTask task(zHost, id + 1); mxs::Semaphore sem; - target->post(&task, &sem, mxs::Worker::EXECUTE_AUTO); + target->execute(&task, &sem, mxs::Worker::EXECUTE_AUTO); sem.wait(); return task.resource(id); diff --git a/server/core/session.cc b/server/core/session.cc index 4ef30d649..4a52f2370 100644 --- a/server/core/session.cc +++ b/server/core/session.cc @@ -359,8 +359,8 @@ static void session_free(MXS_SESSION *session) { // Destroy the service in the main routing worker thread mxs::RoutingWorker* main_worker = mxs::RoutingWorker::get(mxs::RoutingWorker::MAIN); - main_worker->post(std::unique_ptr(new ServiceDestroyTask(service)), - mxs::Worker::EXECUTE_AUTO); + main_worker->execute(std::unique_ptr(new ServiceDestroyTask(service)), + mxs::Worker::EXECUTE_AUTO); } } diff --git a/server/core/worker.cc b/server/core/worker.cc index e9114a2db..c9673902c 100644 --- a/server/core/worker.cc +++ b/server/core/worker.cc @@ -419,7 +419,7 @@ Worker* Worker::get_current() return this_thread.pCurrent_worker; } -bool Worker::post(Task* pTask, Semaphore* pSem, enum execute_mode_t mode) +bool Worker::execute(Task* pTask, Semaphore* pSem, enum execute_mode_t mode) { // No logging here, function must be signal safe. bool rval = true; @@ -444,7 +444,7 @@ bool Worker::post(Task* pTask, Semaphore* pSem, enum execute_mode_t mode) return rval; } -bool Worker::post(std::unique_ptr sTask, enum execute_mode_t mode) +bool Worker::execute(std::unique_ptr sTask, enum execute_mode_t mode) { // No logging here, function must be signal safe. return post_disposable(sTask.release(), mode); @@ -477,7 +477,7 @@ bool Worker::post_disposable(DisposableTask* pTask, enum execute_mode_t mode) return posted; } -bool Worker::post(GenericFunction func, Semaphore* pSem, execute_mode_t mode) +bool Worker::execute(GenericFunction func, Semaphore* pSem, execute_mode_t mode) { class CustomTask : public maxscale::WorkerTask @@ -506,7 +506,7 @@ bool Worker::post(GenericFunction func, Semaphore* pSem, execute_mode_t mode) if (task) { - if (!(rval = post(task, pSem, mode))) + if (!(rval = execute(task, pSem, mode))) { // Posting the task failed, it needs to be deleted now delete task; @@ -519,7 +519,7 @@ bool Worker::post(GenericFunction func, Semaphore* pSem, execute_mode_t mode) bool Worker::call(GenericFunction func, execute_mode_t mode) { Semaphore sem; - return post(func, &sem, mode) && sem.wait(); + return execute(func, &sem, mode) && sem.wait(); } bool Worker::post_message(uint32_t msg_id, intptr_t arg1, intptr_t arg2) diff --git a/server/modules/monitor/mariadbmon/mariadbmon.cc b/server/modules/monitor/mariadbmon/mariadbmon.cc index e902537ef..ec99f26e7 100644 --- a/server/modules/monitor/mariadbmon/mariadbmon.cc +++ b/server/modules/monitor/mariadbmon/mariadbmon.cc @@ -966,7 +966,7 @@ void MariaDBMonitor::disable_setting(const std::string& setting) { Worker* worker = static_cast(mxs_rworker_get(MXS_RWORKER_MAIN)); - worker->post([=]() + worker->execute([=]() { MXS_CONFIG_PARAMETER p = {}; p.name = const_cast(setting.c_str()); diff --git a/server/modules/routing/avrorouter/avro_main.cc b/server/modules/routing/avrorouter/avro_main.cc index 615f68f61..e95fd2881 100644 --- a/server/modules/routing/avrorouter/avro_main.cc +++ b/server/modules/routing/avrorouter/avro_main.cc @@ -335,7 +335,7 @@ static bool conversion_task_ctl(Avro *inst, bool start) if (task.get()) { - worker->post(std::move(task), Worker::EXECUTE_AUTO); + worker->execute(std::move(task), Worker::EXECUTE_AUTO); rval = true; } }