WIP: Allow the adding of any fds to the poll set
This is just a first step in a trial that will allow the addition of any file descriptor to the general poll mechanism and hence allow any i/o to be handled by the worker threads. There is a structure typedef struct mxs_poll_data { void (*handler)(struct mxs_poll_data *data, int wid, uint32_t events); struct { int id; } thread; } MXS_POLL_DATA; that any other structure (e.g. a DCB) encapsulating a file descriptor must have as its first member (a C++ struct could basically derive from it). That structure contains two members; 'handler' and 'thread.id'. Handler is a pointer to a function taking a pointer to a struct mxs_poll_data, a worker thread if and an epoll event mask as argument. So, DCB is modified to have MXS_POLL_DATA as its first member and 'handler' is initialized with a function that *knows* the passed MXS_POLL_DATA can be downcast to a DCB. process_pollq no longer exists, but is now called process_pollq_dcb. The general stuff related to statistics etc. will be moved to poll_waitevents itself after which the whole function is moved to dcb.c. At that point, the handler pointer will be set in dcb_alloc(). Effectively poll.[h|c] will provide a generic mechanism for listening on whatever descriptors and the dcb stuff will be part of dcb.[h|c].
This commit is contained in:
83
include/maxscale/poll_core.h
Normal file
83
include/maxscale/poll_core.h
Normal file
@ -0,0 +1,83 @@
|
||||
#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/bsl.
|
||||
*
|
||||
* Change Date: 2019-07-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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file poll_basic.h The Descriptor Control Block
|
||||
*/
|
||||
|
||||
#include <maxscale/cdefs.h>
|
||||
|
||||
typedef struct mxs_poll_data
|
||||
{
|
||||
/** Pointer to function that knows how to handle events for this particular
|
||||
* 'struct mxs_poll_data' structure.
|
||||
*
|
||||
* @param data The `mxs_poll_data` instance that contained this pointer.
|
||||
* @param wid The worker thread id.
|
||||
* @param events The epoll events.
|
||||
*/
|
||||
void (*handler)(struct mxs_poll_data *data, int wid, uint32_t events);
|
||||
|
||||
struct
|
||||
{
|
||||
/**
|
||||
* The id of the worker thread
|
||||
*/
|
||||
int id;
|
||||
} thread;
|
||||
} MXS_POLL_DATA;
|
||||
|
||||
/**
|
||||
* A file descriptor should be added to the poll set of all workers.
|
||||
*/
|
||||
#define MXS_WORKER_ALL -1
|
||||
|
||||
/**
|
||||
* A file descriptor should be added to the poll set of some worker.
|
||||
*/
|
||||
#define MXS_WORKER_ANY -2
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return 0 on success, non-zero on failure.
|
||||
*/
|
||||
int 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 0 on success, non-zero on failure.
|
||||
*/
|
||||
int poll_remove_fd_from_worker(int wid, int fd);
|
Reference in New Issue
Block a user