MXS-1915 Remove id from mxs::Worker

The id has now been moved from mxs::Worker to mxs::RoutingWorker
and the implications are felt in many places.

The primary need for the id was to be able to access worker specfic
data, maintained outside of a routing worker, when given a worker
(the id is used to index into an array). Slightly related to that
was the need to be able to iterate over all workers. That obviously
implies some kind of collection.

That causes all sorts of issues if there is a need for being able
to create and destroy a worker at runtime. With the id removed from
mxs::Worker all those issues are gone, and its perfectly ok to create
and destory mxs::Workers as needed.

Further, while there is a need to broadcast a particular message to
all _routing_ workers, it hardly makes sense to broadcast a particular
message too _all_ workers. Consequently, only routing workers are kept
in a collection and all static member functions dealing with all
workers (e.g. broadcast) have now been moved to mxs::RoutingWorker.

Now, instead of passing the id around we instead deal directly
with the worker pointer. Later the data in all those external arrays
will be moved into mxs::[Worker|RoutingWorker] so that worker related
data is maintained in exactly one place.
This commit is contained in:
Johan Wikman
2018-06-21 14:29:29 +03:00
parent 86b5238aaf
commit 8ea7d8898a
17 changed files with 719 additions and 879 deletions

View File

@ -39,12 +39,13 @@ struct mxs_poll_data;
* 'struct mxs_poll_data' structure.
*
* @param data The `mxs_poll_data` instance that contained this function pointer.
* @param wid The worker thread id.
* @param worker The worker.
* @param events The epoll events.
*
* @return A combination of mxs_poll_action_t enumeration values.
*/
typedef uint32_t (*mxs_poll_handler_t)(struct mxs_poll_data* data, int wid, uint32_t events);
// TODO: Change worker to mxs::Worker once this is C++-ified.
typedef uint32_t (*mxs_poll_handler_t)(struct mxs_poll_data* data, void* worker, uint32_t events);
typedef struct mxs_poll_data
{
@ -52,45 +53,4 @@ typedef struct mxs_poll_data
void* owner; /*< Owning worker. */
} MXS_POLL_DATA;
/**
* A file descriptor should be added to the poll set of all workers.
*/
#define MXS_WORKER_ALL -1
/**
* Add a file descriptor with associated data to the poll set.
*
* @param wid `MXS_WORKER_ALL` if the file descriptor should be added to the
* poll set of all workers, `MXS_WORKER_ANY` if the file descriptor
* should be added to some worker, otherwise the id of a worker.
* @param fd The file descriptor to be added.
* @param events Mask of epoll event types.
* @param data The structure containing the file descriptor to be
* added.
*
* data->handler : Handler that knows how to deal with events
* for this particular type of 'struct mxs_poll_data'.
* data->thread.id: Will be updated by `poll_add_fd_to_worker`.
*
* @attention If the descriptor should be added to all workers, then the worker
* thread id will be 0.
*
* @attention The provided file descriptor *must* be non-blocking.
*
* @return True on success, false on failure.
*/
bool poll_add_fd_to_worker(int wid, int fd, uint32_t events, MXS_POLL_DATA* data);
/**
* Remove a file descriptor from a poll set.
*
* @param wid `MXS_WORKER_ALL` if the file descriptor should be removed from
* the poll set of all workers; otherwise the id of a worker.
* @param fd The file descriptor to be removed.
*
* @return True on success, false on failure.
*/
bool poll_remove_fd_from_worker(int wid, int fd);
MXS_END_DECLS