MXS-1929: Add worker local storage of data

Data can now be stored on thread-local storage of the worker. By acquiring
a unique handle from the worker, a module can store a thread-local
value.

This functionality will be used to store configurations that are sometimes
updated at runtime but are largely read-only. By avoiding shared data
altogether, performance is not affected. The only synchronization that is
done is on update.

Also added a helper functions for broadcasting tasks on all routing
workers. With the old mxs_rworker_broadcast_message function, if a
function call was broadcasted it was always queued for execution. The
mxs_rworker_broadcast will immediately execute the task on the local
worker and queue it for execution of other routing workers.
This commit is contained in:
Markus Mäkelä
2018-07-26 10:10:05 +03:00
parent a833f39196
commit ff07009d8c
3 changed files with 187 additions and 0 deletions

View File

@ -997,6 +997,57 @@ private:
const char* m_zHost;
};
class FunctionTask: public maxscale::WorkerDisposableTask
{
public:
FunctionTask(std::function<void ()> cb):
m_cb(cb)
{
}
void execute(Worker& worker)
{
m_cb();
}
protected:
std::function<void ()> m_cb;
};
}
size_t mxs_rworker_broadcast(void (*cb)(void* data), void* data)
{
return RoutingWorker::broadcast(std::auto_ptr<FunctionTask>(new FunctionTask([&]()
{
cb(data);
})));
}
uint64_t mxs_rworker_create_key()
{
return RoutingWorker::create_key();
}
void mxs_rworker_set_data(uint64_t key, void* data, void (*callback)(void*))
{
RoutingWorker::get_current()->set_data(key, data, callback);
}
void* mxs_rworker_get_data(uint64_t key)
{
return RoutingWorker::get_current()->get_data(key);
}
void mxs_rworker_delete_data(uint64_t key)
{
auto func = [key]()
{
RoutingWorker::get_current()->delete_data(key);
};
std::auto_ptr<FunctionTask> task(new FunctionTask(func));
RoutingWorker::broadcast(task);
}
json_t* mxs_rworker_to_json(const char* zHost, int id)