
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.
80 lines
1.9 KiB
C
80 lines
1.9 KiB
C
#pragma once
|
|
/*
|
|
* Copyright (c) 2016 MariaDB Corporation Ab
|
|
*
|
|
* Use of this software is governed by the Business Source License included
|
|
* in the LICENSE.TXT file and at www.mariadb.com/bsl11.
|
|
*
|
|
* Change Date: 2022-01-01
|
|
*
|
|
* On the date above, in accordance with the Business Source License, use
|
|
* of this software will be governed by version 2 or later of the General
|
|
* Public License.
|
|
*/
|
|
|
|
#include <maxscale/cdefs.h>
|
|
#include <maxscale/poll.h>
|
|
#include <maxscale/thread.h>
|
|
#include <maxscale/jansson.h>
|
|
|
|
MXS_BEGIN_DECLS
|
|
|
|
typedef struct mxs_worker
|
|
{
|
|
} MXS_WORKER;
|
|
|
|
enum mxs_worker_msg_id
|
|
{
|
|
/**
|
|
* Ping message.
|
|
*
|
|
* arg1: 0
|
|
* arg2: NULL or pointer to dynamically allocated NULL-terminated string,
|
|
* to be freed by worker.
|
|
*/
|
|
MXS_WORKER_MSG_PING,
|
|
|
|
/**
|
|
* Shutdown message.
|
|
*
|
|
* arg1: 0
|
|
* arg2: NULL
|
|
*/
|
|
MXS_WORKER_MSG_SHUTDOWN,
|
|
|
|
/**
|
|
* Function call message.
|
|
*
|
|
* arg1: Pointer to function with the prototype: void (*)(MXS_WORKER*, void* arg2);
|
|
* arg2: Second argument for the function passed in arg1.
|
|
*/
|
|
MXS_WORKER_MSG_CALL
|
|
};
|
|
|
|
/**
|
|
* Return the current worker.
|
|
*
|
|
* @return A worker, or NULL if there is no current worker.
|
|
*/
|
|
MXS_WORKER* mxs_worker_get_current();
|
|
|
|
/**
|
|
* Post a message to a worker.
|
|
*
|
|
* @param worker The worker to whom the message should be sent.
|
|
* @param msg_id The message id.
|
|
* @param arg1 Message specific first argument.
|
|
* @param arg2 Message specific second argument.
|
|
*
|
|
* @return True if the message could be sent, false otherwise. If the message
|
|
* posting fails, errno is set appropriately.
|
|
*
|
|
* @attention The return value tells *only* whether the message could be sent,
|
|
* *not* that it has reached the worker.
|
|
*
|
|
* @attention This function is signal safe.
|
|
*/
|
|
bool mxs_worker_post_message(MXS_WORKER* worker, uint32_t msg_id, intptr_t arg1, intptr_t arg2);
|
|
|
|
MXS_END_DECLS
|