MXS-2008 Add maxbase/poll.[h|hh]
Remove maxscale/poll_core.h
This commit is contained in:
@ -115,7 +115,7 @@ static bool dcb_add_to_worker(Worker* worker, DCB *dcb, uint32_t events);
|
||||
static DCB *dcb_find_free();
|
||||
static void dcb_remove_from_list(DCB *dcb);
|
||||
|
||||
static uint32_t dcb_poll_handler(MXS_POLL_DATA *data, void* worker, uint32_t events);
|
||||
static uint32_t dcb_poll_handler(MXB_POLL_DATA *data, void* worker, uint32_t events);
|
||||
static uint32_t dcb_process_poll_events(DCB *dcb, uint32_t ev);
|
||||
static bool dcb_session_check(DCB *dcb, const char *);
|
||||
static int upstream_throttle_callback(DCB *dcb, DCB_REASON reason, void *userdata);
|
||||
@ -2985,7 +2985,7 @@ static uint32_t dcb_process_poll_events(DCB *dcb, uint32_t events)
|
||||
ss_dassert(owner == RoutingWorker::get_current() ||
|
||||
dcb->dcb_role == DCB_ROLE_SERVICE_LISTENER);
|
||||
|
||||
uint32_t rc = MXS_POLL_NOP;
|
||||
uint32_t rc = MXB_POLL_NOP;
|
||||
|
||||
/* It isn't obvious that this is impossible */
|
||||
/* ss_dassert(dcb->state != DCB_STATE_DISCONNECTED); */
|
||||
@ -3021,7 +3021,7 @@ static uint32_t dcb_process_poll_events(DCB *dcb, uint32_t events)
|
||||
|
||||
if (eno == 0)
|
||||
{
|
||||
rc |= MXS_POLL_WRITE;
|
||||
rc |= MXB_POLL_WRITE;
|
||||
|
||||
if (dcb_session_check(dcb, "write_ready"))
|
||||
{
|
||||
@ -3050,7 +3050,7 @@ static uint32_t dcb_process_poll_events(DCB *dcb, uint32_t events)
|
||||
"Accept in fd %d",
|
||||
pthread_self(),
|
||||
dcb->fd);
|
||||
rc |= MXS_POLL_ACCEPT;
|
||||
rc |= MXB_POLL_ACCEPT;
|
||||
|
||||
if (dcb_session_check(dcb, "accept"))
|
||||
{
|
||||
@ -3065,7 +3065,7 @@ static uint32_t dcb_process_poll_events(DCB *dcb, uint32_t events)
|
||||
pthread_self(),
|
||||
dcb,
|
||||
dcb->fd);
|
||||
rc |= MXS_POLL_READ;
|
||||
rc |= MXB_POLL_READ;
|
||||
|
||||
if (dcb_session_check(dcb, "read"))
|
||||
{
|
||||
@ -3098,7 +3098,7 @@ static uint32_t dcb_process_poll_events(DCB *dcb, uint32_t events)
|
||||
eno,
|
||||
strerror_r(eno, errbuf, sizeof(errbuf)));
|
||||
}
|
||||
rc |= MXS_POLL_ERROR;
|
||||
rc |= MXB_POLL_ERROR;
|
||||
|
||||
if (dcb_session_check(dcb, "error"))
|
||||
{
|
||||
@ -3119,7 +3119,7 @@ static uint32_t dcb_process_poll_events(DCB *dcb, uint32_t events)
|
||||
dcb->fd,
|
||||
eno,
|
||||
strerror_r(eno, errbuf, sizeof(errbuf)));
|
||||
rc |= MXS_POLL_HUP;
|
||||
rc |= MXB_POLL_HUP;
|
||||
if ((dcb->flags & DCBF_HUNG) == 0)
|
||||
{
|
||||
dcb->flags |= DCBF_HUNG;
|
||||
@ -3145,7 +3145,7 @@ static uint32_t dcb_process_poll_events(DCB *dcb, uint32_t events)
|
||||
dcb->fd,
|
||||
eno,
|
||||
strerror_r(eno, errbuf, sizeof(errbuf)));
|
||||
rc |= MXS_POLL_HUP;
|
||||
rc |= MXB_POLL_HUP;
|
||||
|
||||
if ((dcb->flags & DCBF_HUNG) == 0)
|
||||
{
|
||||
@ -3186,7 +3186,7 @@ static uint32_t dcb_handler(DCB* dcb, uint32_t events)
|
||||
return rv;
|
||||
}
|
||||
|
||||
static uint32_t dcb_poll_handler(MXS_POLL_DATA *data, void* worker, uint32_t events)
|
||||
static uint32_t dcb_poll_handler(MXB_POLL_DATA *data, void* worker, uint32_t events)
|
||||
{
|
||||
uint32_t rval = 0;
|
||||
DCB *dcb = (DCB*)data;
|
||||
@ -3406,7 +3406,7 @@ private:
|
||||
|
||||
}
|
||||
|
||||
static bool add_fd_to_routing_workers(int fd, uint32_t events, MXS_POLL_DATA* data)
|
||||
static bool add_fd_to_routing_workers(int fd, uint32_t events, MXB_POLL_DATA* data)
|
||||
{
|
||||
bool rv = true;
|
||||
void* previous_owner = data->owner;
|
||||
@ -3447,7 +3447,7 @@ static bool dcb_add_to_worker(Worker* worker, DCB* dcb, uint32_t events)
|
||||
ss_dassert(dcb->dcb_role == DCB_ROLE_SERVICE_LISTENER);
|
||||
|
||||
// A listening DCB, we add it immediately.
|
||||
if (add_fd_to_routing_workers(dcb->fd, events, (MXS_POLL_DATA*)dcb))
|
||||
if (add_fd_to_routing_workers(dcb->fd, events, (MXB_POLL_DATA*)dcb))
|
||||
{
|
||||
// If this takes place on the main thread (all listening DCBs are
|
||||
// stored on the main thread)...
|
||||
@ -3483,7 +3483,7 @@ static bool dcb_add_to_worker(Worker* worker, DCB* dcb, uint32_t events)
|
||||
{
|
||||
// If the DCB should end up on the current thread, we can both add it
|
||||
// to the epoll-instance and to the DCB book-keeping immediately.
|
||||
if (worker->add_fd(dcb->fd, events, (MXS_POLL_DATA*)dcb))
|
||||
if (worker->add_fd(dcb->fd, events, (MXB_POLL_DATA*)dcb))
|
||||
{
|
||||
dcb_add_to_list(dcb);
|
||||
rv = true;
|
||||
|
@ -28,7 +28,7 @@ namespace maxscale
|
||||
{
|
||||
|
||||
class RoutingWorker : public Worker
|
||||
, private MXS_POLL_DATA
|
||||
, private MXB_POLL_DATA
|
||||
{
|
||||
RoutingWorker(const RoutingWorker&) = delete;
|
||||
RoutingWorker& operator = (const RoutingWorker&) = delete;
|
||||
@ -81,7 +81,7 @@ public:
|
||||
*
|
||||
* @return True, if the descriptor could be added, false otherwise.
|
||||
*/
|
||||
static bool add_shared_fd(int fd, uint32_t events, MXS_POLL_DATA* pData);
|
||||
static bool add_shared_fd(int fd, uint32_t events, MXB_POLL_DATA* pData);
|
||||
|
||||
/**
|
||||
* Remove a file descriptor from the epoll instance shared between all workers.
|
||||
@ -429,7 +429,7 @@ private:
|
||||
|
||||
void delete_zombies();
|
||||
|
||||
static uint32_t epoll_instance_handler(struct mxs_poll_data* data, void* worker, uint32_t events);
|
||||
static uint32_t epoll_instance_handler(MXB_POLL_DATA* data, void* worker, uint32_t events);
|
||||
uint32_t handle_epoll_events(uint32_t events);
|
||||
};
|
||||
|
||||
|
@ -52,7 +52,7 @@ namespace maxscale
|
||||
{
|
||||
|
||||
MessageQueue::MessageQueue(Handler* pHandler, int read_fd, int write_fd)
|
||||
: MxsPollData(&MessageQueue::poll_handler)
|
||||
: mxb::PollData(&MessageQueue::poll_handler)
|
||||
, m_handler(*pHandler)
|
||||
, m_read_fd(read_fd)
|
||||
, m_write_fd(write_fd)
|
||||
@ -267,7 +267,7 @@ Worker* MessageQueue::remove_from_worker()
|
||||
|
||||
uint32_t MessageQueue::handle_poll_events(Worker* pWorker, uint32_t events)
|
||||
{
|
||||
uint32_t rc = MXS_POLL_NOP;
|
||||
uint32_t rc = MXB_POLL_NOP;
|
||||
|
||||
ss_dassert(pWorker == m_pWorker);
|
||||
|
||||
@ -308,14 +308,14 @@ uint32_t MessageQueue::handle_poll_events(Worker* pWorker, uint32_t events)
|
||||
}
|
||||
while ((n != 0) && (n != -1));
|
||||
|
||||
rc = MXS_POLL_READ;
|
||||
rc = MXB_POLL_READ;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
//static
|
||||
uint32_t MessageQueue::poll_handler(MXS_POLL_DATA* pData, void* pWorker, uint32_t events)
|
||||
uint32_t MessageQueue::poll_handler(MXB_POLL_DATA* pData, void* pWorker, uint32_t events)
|
||||
{
|
||||
MessageQueue* pThis = static_cast<MessageQueue*>(pData);
|
||||
|
||||
|
@ -169,8 +169,8 @@ namespace maxscale
|
||||
RoutingWorker::RoutingWorker()
|
||||
: m_id(next_worker_id())
|
||||
{
|
||||
MXS_POLL_DATA::handler = &RoutingWorker::epoll_instance_handler;
|
||||
MXS_POLL_DATA::owner = this;
|
||||
MXB_POLL_DATA::handler = &RoutingWorker::epoll_instance_handler;
|
||||
MXB_POLL_DATA::owner = this;
|
||||
}
|
||||
|
||||
RoutingWorker::~RoutingWorker()
|
||||
@ -296,7 +296,7 @@ void RoutingWorker::finish()
|
||||
}
|
||||
|
||||
//static
|
||||
bool RoutingWorker::add_shared_fd(int fd, uint32_t events, MXS_POLL_DATA* pData)
|
||||
bool RoutingWorker::add_shared_fd(int fd, uint32_t events, MXB_POLL_DATA* pData)
|
||||
{
|
||||
bool rv = true;
|
||||
|
||||
@ -497,7 +497,7 @@ RoutingWorker* RoutingWorker::create(int epoll_listener_fd)
|
||||
{
|
||||
struct epoll_event ev;
|
||||
ev.events = EPOLLIN;
|
||||
MXS_POLL_DATA* pData = pThis;
|
||||
MXB_POLL_DATA* pData = pThis;
|
||||
ev.data.ptr = pData; // Necessary for pointer adjustment, otherwise downcast will not work.
|
||||
|
||||
// The shared epoll instance descriptor is *not* added using EPOLLET (edge-triggered)
|
||||
@ -547,7 +547,7 @@ void RoutingWorker::epoll_tick()
|
||||
* @return What actions were performed.
|
||||
*/
|
||||
//static
|
||||
uint32_t RoutingWorker::epoll_instance_handler(struct mxs_poll_data* pData, void* pWorker, uint32_t events)
|
||||
uint32_t RoutingWorker::epoll_instance_handler(MXB_POLL_DATA* pData, void* pWorker, uint32_t events)
|
||||
{
|
||||
RoutingWorker* pThis = static_cast<RoutingWorker*>(pData);
|
||||
ss_dassert(pThis == pWorker);
|
||||
@ -569,7 +569,7 @@ uint32_t RoutingWorker::handle_epoll_events(uint32_t events)
|
||||
// We extract just one event
|
||||
int nfds = epoll_wait(this_unit.epoll_listener_fd, epoll_events, 1, 0);
|
||||
|
||||
uint32_t actions = MXS_POLL_NOP;
|
||||
uint32_t actions = MXB_POLL_NOP;
|
||||
|
||||
if (nfds == -1)
|
||||
{
|
||||
@ -582,7 +582,7 @@ uint32_t RoutingWorker::handle_epoll_events(uint32_t events)
|
||||
else
|
||||
{
|
||||
MXS_DEBUG("1 event for worker %d.", m_id);
|
||||
MXS_POLL_DATA* pData = static_cast<MXS_POLL_DATA*>(epoll_events[0].data.ptr);
|
||||
MXB_POLL_DATA* pData = static_cast<MXB_POLL_DATA*>(epoll_events[0].data.ptr);
|
||||
|
||||
actions = pData->handler(pData, this, epoll_events[0].events);
|
||||
}
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include <sstream>
|
||||
#include <sys/timerfd.h>
|
||||
|
||||
#include <maxbase/atomic.h>
|
||||
#include <maxscale/log.h>
|
||||
|
||||
#define WORKER_ABSENT_ID -1
|
||||
@ -181,8 +180,8 @@ WorkerTimer::WorkerTimer(Worker* pWorker)
|
||||
: m_fd(create_timerfd())
|
||||
, m_pWorker(pWorker)
|
||||
{
|
||||
MXS_POLL_DATA::handler = handler;
|
||||
MXS_POLL_DATA::owner = m_pWorker;
|
||||
MXB_POLL_DATA::handler = handler;
|
||||
MXB_POLL_DATA::owner = m_pWorker;
|
||||
|
||||
if (m_fd != -1)
|
||||
{
|
||||
@ -252,11 +251,11 @@ uint32_t WorkerTimer::handle(Worker* pWorker, uint32_t events)
|
||||
|
||||
tick();
|
||||
|
||||
return MXS_POLL_READ;
|
||||
return MXB_POLL_READ;
|
||||
}
|
||||
|
||||
//static
|
||||
uint32_t WorkerTimer::handler(MXS_POLL_DATA* pThis, void* pWorker, uint32_t events)
|
||||
uint32_t WorkerTimer::handler(MXB_POLL_DATA* pThis, void* pWorker, uint32_t events)
|
||||
{
|
||||
return static_cast<WorkerTimer*>(pThis)->handle(static_cast<Worker*>(pWorker), events);
|
||||
}
|
||||
@ -358,7 +357,7 @@ void Worker::get_descriptor_counts(uint32_t* pnCurrent, uint64_t* pnTotal)
|
||||
*pnTotal = atomic_load_uint64(&m_nTotal_descriptors);
|
||||
}
|
||||
|
||||
bool Worker::add_fd(int fd, uint32_t events, MXS_POLL_DATA* pData)
|
||||
bool Worker::add_fd(int fd, uint32_t events, MXB_POLL_DATA* pData)
|
||||
{
|
||||
bool rv = true;
|
||||
|
||||
@ -843,31 +842,31 @@ void Worker::poll_waitevents()
|
||||
|
||||
m_statistics.maxqtime = MXS_MAX(m_statistics.maxqtime, qtime);
|
||||
|
||||
MXS_POLL_DATA *data = (MXS_POLL_DATA*)events[i].data.ptr;
|
||||
MXB_POLL_DATA *data = (MXB_POLL_DATA*)events[i].data.ptr;
|
||||
|
||||
uint32_t actions = data->handler(data, this, events[i].events);
|
||||
|
||||
if (actions & MXS_POLL_ACCEPT)
|
||||
if (actions & MXB_POLL_ACCEPT)
|
||||
{
|
||||
atomic_add_int64(&m_statistics.n_accept, 1);
|
||||
}
|
||||
|
||||
if (actions & MXS_POLL_READ)
|
||||
if (actions & MXB_POLL_READ)
|
||||
{
|
||||
atomic_add_int64(&m_statistics.n_read, 1);
|
||||
}
|
||||
|
||||
if (actions & MXS_POLL_WRITE)
|
||||
if (actions & MXB_POLL_WRITE)
|
||||
{
|
||||
atomic_add_int64(&m_statistics.n_write, 1);
|
||||
}
|
||||
|
||||
if (actions & MXS_POLL_HUP)
|
||||
if (actions & MXB_POLL_HUP)
|
||||
{
|
||||
atomic_add_int64(&m_statistics.n_hup, 1);
|
||||
}
|
||||
|
||||
if (actions & MXS_POLL_ERROR)
|
||||
if (actions & MXB_POLL_ERROR)
|
||||
{
|
||||
atomic_add_int64(&m_statistics.n_error, 1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user