Move execute_worker_task into mxs::Worker
The function has use outside of the monitors as it makes execution of worker tasks much more convenient. Currently, this change only moves the code and takes it into use: there should be no functional changes.
This commit is contained in:
@ -2968,45 +2968,4 @@ void MonitorInstance::run_one_tick()
|
||||
store_server_journal(m_monitor, m_master);
|
||||
}
|
||||
|
||||
bool MonitorInstance::execute_worker_task(GenericFunction func, execute_mode_t mode)
|
||||
{
|
||||
/* The worker message system works on objects of class Task, each representing a different action.
|
||||
* Let's use a function object inside a task to construct a generic action. */
|
||||
class CustomTask : public maxscale::Worker::Task
|
||||
{
|
||||
public:
|
||||
CustomTask(GenericFunction func)
|
||||
: m_func(func)
|
||||
{}
|
||||
|
||||
private:
|
||||
GenericFunction m_func;
|
||||
void execute(maxscale::Worker& worker)
|
||||
{
|
||||
m_func();
|
||||
delete this; // Ok, since this object is not touched afterwards.
|
||||
}
|
||||
};
|
||||
|
||||
CustomTask* task = new (std::nothrow) CustomTask(func);
|
||||
bool sent = false;
|
||||
|
||||
if (mode == Worker::EXECUTE_AUTO)
|
||||
{
|
||||
maxscale::Semaphore done(0);
|
||||
/* Although the current method is being ran in the admin thread, 'post' sends the task to the
|
||||
* worker thread of "this". */
|
||||
sent = post(task, &done, mode);
|
||||
if (sent)
|
||||
{
|
||||
done.wait();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sent = post(task, NULL, mode);
|
||||
}
|
||||
return sent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user