MXS-1915 Allow Worker to be used stand-alone

It's no longer necessary to inherit from Worker in order to use
it, but it can now be used in a stand-alone fashion. This fits
the MonitorInstance use-case better.
This commit is contained in:
Johan Wikman
2018-06-18 14:58:28 +03:00
parent 063e9b9a36
commit 5cf6a9ed22
2 changed files with 30 additions and 6 deletions

View File

@ -475,6 +475,11 @@ private:
Worker* m_pWorker; /**< The worker in whose context the timer runs. */ Worker* m_pWorker; /**< The worker in whose context the timer runs. */
}; };
/**
* A Worker is a class capable of asynchronously processing events
* associated with file descriptors. Internally Worker has a thread
* and an epoll-instance of its own.
*/
class Worker : public MXS_WORKER class Worker : public MXS_WORKER
, private MessageQueue::Handler , private MessageQueue::Handler
{ {
@ -570,6 +575,9 @@ public:
*/ */
static void finish(); static void finish();
Worker();
virtual ~Worker();
/** /**
* Returns the id of the worker * Returns the id of the worker
* *
@ -1026,25 +1034,28 @@ public:
bool cancel_delayed_call(uint32_t id); bool cancel_delayed_call(uint32_t id);
protected: protected:
Worker();
virtual ~Worker();
/** /**
* Called by Worker::run() before starting the epoll loop. * Called by Worker::run() before starting the epoll loop.
* *
* Default implementation returns True.
*
* @return True, if the epoll loop should be started, false otherwise. * @return True, if the epoll loop should be started, false otherwise.
*/ */
virtual bool pre_run() = 0; virtual bool pre_run();
/** /**
* Called by Worker::run() after the epoll loop has finished. * Called by Worker::run() after the epoll loop has finished.
*
* Default implementation does nothing.
*/ */
virtual void post_run() = 0; virtual void post_run();
/** /**
* Called by Worker::run() once per epoll loop. * Called by Worker::run() once per epoll loop.
*
* Default implementation does nothing.
*/ */
virtual void epoll_tick() = 0; virtual void epoll_tick();
/** /**
* Helper for resolving epoll-errors. In case of fatal ones, SIGABRT * Helper for resolving epoll-errors. In case of fatal ones, SIGABRT

View File

@ -935,6 +935,19 @@ void Worker::thread_main(void* pArg)
pWorker->run(); pWorker->run();
} }
bool Worker::pre_run()
{
return true;
}
void Worker::post_run()
{
}
void Worker::epoll_tick()
{
}
// static // static
void Worker::resolve_poll_error(int fd, int errornum, int op) void Worker::resolve_poll_error(int fd, int errornum, int op)
{ {