MXS-1915 Replace worker id with worker pointer

To get rid of the need that a Worker must have an id, we store
in the MXS_POLL_DATA structure a pointer to the owning worker
instead of the id of the owning worker. This also allows some
further cleanup as the need for switching back and forth between
the id and the worker disappears.

The id will be moved from Worker to RoutingWorker as there
currently is a fair amount of code that assumes that the id of
routing workers start from 0.
This commit is contained in:
Johan Wikman
2018-06-20 14:54:20 +03:00
parent 241c9b645d
commit 86b5238aaf
8 changed files with 73 additions and 66 deletions

View File

@ -67,30 +67,30 @@ static bool add_fd_to_worker(int wid, int fd, uint32_t events, MXS_POLL_DATA* da
static bool add_fd_to_routing_workers(int fd, uint32_t events, MXS_POLL_DATA* data)
{
bool rv = true;
int thread_id = data->thread.id;
void* previous_owner = data->owner;
rv = RoutingWorker::add_shared_fd(fd, events, data);
if (rv)
{
// The DCB will appear on the list of the calling thread.
int wid = RoutingWorker::get_current_id();
RoutingWorker* worker = RoutingWorker::get_current();
if (wid == -1)
if (!worker)
{
// TODO: Listeners are created before the workers have been started.
// TODO: Hence the returned id will be -1. We change it to 0, which in
// TODO: practice will mean that they will end up on the Worker running
// TODO: in the main thread. This needs to be sorted out.
wid = 0;
worker = RoutingWorker::get(RoutingWorker::MAIN);
}
data->thread.id = wid;
data->owner = worker;
}
else
{
// Restore the situation.
data->thread.id = thread_id;
data->owner = previous_owner;
}
return rv;