From b18467e17e01bb148da5111b720dd3994f2f006f Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Thu, 31 Jan 2019 10:04:55 +0200 Subject: [PATCH] Add direct mode to Worker::execute() Sometimes that's what you want, but primarily for completeness' sake and it makes AUTO more sensical as it essentially chooses beteen DIRECT and QUEUED mode. --- maxutils/maxbase/include/maxbase/worker.hh | 5 +++-- maxutils/maxbase/src/worker.cc | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/maxutils/maxbase/include/maxbase/worker.hh b/maxutils/maxbase/include/maxbase/worker.hh index ebb0e1dbe..eb10b202d 100644 --- a/maxutils/maxbase/include/maxbase/worker.hh +++ b/maxutils/maxbase/include/maxbase/worker.hh @@ -306,8 +306,9 @@ public: enum execute_mode_t { - EXECUTE_AUTO, /**< Execute tasks immediately */ - EXECUTE_QUEUED /**< Only queue tasks for execution */ + EXECUTE_DIRECT, /**< Always execute directly using the calling thread/worker. */ + EXECUTE_QUEUED, /**< Always execute via the event loop using this thread/worker. */ + EXECUTE_AUTO, /**< If calling thread/worker is this worker, call directly otherwise queued. */ }; struct Call diff --git a/maxutils/maxbase/src/worker.cc b/maxutils/maxbase/src/worker.cc index c5b5e1e09..2d3c74067 100644 --- a/maxutils/maxbase/src/worker.cc +++ b/maxutils/maxbase/src/worker.cc @@ -414,7 +414,8 @@ bool Worker::execute(Task* pTask, mxb::Semaphore* pSem, enum execute_mode_t mode // No logging here, function must be signal safe. bool rval = true; - if (mode == Worker::EXECUTE_AUTO && Worker::get_current() == this) + if ((mode == Worker::EXECUTE_DIRECT) + || (mode == Worker::EXECUTE_AUTO && Worker::get_current() == this)) { pTask->execute(*this); @@ -447,7 +448,8 @@ bool Worker::post_disposable(DisposableTask* pTask, enum execute_mode_t mode) pTask->inc_ref(); - if (mode == Worker::EXECUTE_AUTO && Worker::get_current() == this) + if ((mode == Worker::EXECUTE_DIRECT) + || (mode == Worker::EXECUTE_AUTO && Worker::get_current() == this)) { pTask->execute(*this); pTask->dec_ref();