MXS-1848 Move Worker from internal to public include dir
maxscale::Worker needs to be public if monitors should be implementable using it.
This commit is contained in:
@ -55,11 +55,11 @@
|
||||
#include <maxscale/spinlock.h>
|
||||
#include <maxscale/utils.h>
|
||||
#include <maxscale/semaphore.hh>
|
||||
#include <maxscale/workertask.hh>
|
||||
|
||||
#include "internal/modules.h"
|
||||
#include "internal/routingworker.hh"
|
||||
#include "internal/session.h"
|
||||
#include "internal/workertask.hh"
|
||||
|
||||
using maxscale::RoutingWorker;
|
||||
using maxscale::Worker;
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <maxscale/housekeeper.h>
|
||||
#include <maxscale/log_manager.h>
|
||||
#include <maxscale/maxscale.h>
|
||||
#include <maxscale/messagequeue.hh>
|
||||
#include <maxscale/mysql_utils.h>
|
||||
#include <maxscale/paths.h>
|
||||
#include <maxscale/query_classifier.h>
|
||||
@ -56,7 +57,6 @@
|
||||
#include "internal/admin.hh"
|
||||
#include "internal/config.h"
|
||||
#include "internal/maxscale.h"
|
||||
#include "internal/messagequeue.hh"
|
||||
#include "internal/modules.h"
|
||||
#include "internal/monitor.h"
|
||||
#include "internal/poll.h"
|
||||
|
@ -1,207 +0,0 @@
|
||||
#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: 2020-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/cppdefs.hh>
|
||||
#include <maxscale/poll_core.hh>
|
||||
|
||||
namespace maxscale
|
||||
{
|
||||
|
||||
class MessageQueue;
|
||||
class Worker;
|
||||
|
||||
/**
|
||||
* An instance of @c MessageQueueMessage can be sent over a @c MessageQueue from
|
||||
* one context to another. The instance will be copied verbatim without any
|
||||
* interpretation, so if the same message is sent to multiple recipients it is
|
||||
* the caller's and recipient's responsibility to manage the lifetime and
|
||||
* concurrent access of anything possibly pointed to from the message.
|
||||
*/
|
||||
class MessageQueueMessage /* final */
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param id The id of the message. The meaning is an affair between the sender
|
||||
* and the recipient.
|
||||
* @param arg1 First argument.
|
||||
* @param arg2 Second argument.
|
||||
*/
|
||||
explicit MessageQueueMessage(uint64_t id = 0, intptr_t arg1 = 0, intptr_t arg2 = 0)
|
||||
: m_id(id)
|
||||
, m_arg1(arg1)
|
||||
, m_arg2(arg2)
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t id() const
|
||||
{
|
||||
return m_id;
|
||||
}
|
||||
|
||||
intptr_t arg1() const
|
||||
{
|
||||
return m_arg1;
|
||||
}
|
||||
|
||||
intptr_t arg2() const
|
||||
{
|
||||
return m_arg2;
|
||||
}
|
||||
|
||||
MessageQueueMessage& set_id(uint64_t id)
|
||||
{
|
||||
m_id = id;
|
||||
return *this;
|
||||
}
|
||||
|
||||
MessageQueueMessage& set_arg1(intptr_t arg1)
|
||||
{
|
||||
m_arg1 = arg1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
MessageQueueMessage& set_arg2(intptr_t arg2)
|
||||
{
|
||||
m_arg2 = arg2;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
uint64_t m_id;
|
||||
intptr_t m_arg1;
|
||||
intptr_t m_arg2;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A @c MessageQueueHandler will be delivered messages received over a
|
||||
* @c MessageQueue.
|
||||
*/
|
||||
class MessageQueueHandler
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Message delivery.
|
||||
*
|
||||
* @param queue The queue over which the message was received.
|
||||
* @param message The message.
|
||||
*/
|
||||
virtual void handle_message(MessageQueue& queue, const MessageQueueMessage& message) = 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The class @c MessageQueue provides a cross thread message queue implemented
|
||||
* on top of a pipe.
|
||||
*/
|
||||
class MessageQueue : private MxsPollData
|
||||
{
|
||||
MessageQueue(const MessageQueue&);
|
||||
MessageQueue& operator = (const MessageQueue&);
|
||||
|
||||
public:
|
||||
typedef MessageQueueHandler Handler;
|
||||
typedef MessageQueueMessage Message;
|
||||
|
||||
/**
|
||||
* Initializes the message queue mechanism. To be called once at
|
||||
* process startup.
|
||||
*
|
||||
* @return True if the initialization succeeded, false otherwise.
|
||||
*/
|
||||
static bool init();
|
||||
|
||||
|
||||
/**
|
||||
* Finalizes the message queue mechanism. To be called once at
|
||||
* process shutdown, if the initialization succeeded.
|
||||
*/
|
||||
static void finish();
|
||||
|
||||
/**
|
||||
* Creates a @c MessageQueue with the provided handler.
|
||||
*
|
||||
* @param pHandler The handler that will receive the messages sent over the
|
||||
* message queue. Note that the handler *must* remain valid
|
||||
* for the lifetime of the @c MessageQueue.
|
||||
*
|
||||
* @return A pointer to a new @c MessageQueue or NULL if an error occurred.
|
||||
*
|
||||
* @attention Before the message queue can be used, it must be added to
|
||||
* a worker.
|
||||
*/
|
||||
static MessageQueue* create(Handler* pHandler);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
* Removes itself If still added to a worker and closes the pipe.
|
||||
*/
|
||||
~MessageQueue();
|
||||
|
||||
/**
|
||||
* Posts a message over the queue to the handler provided when the
|
||||
* @c MessageQueue was created.
|
||||
*
|
||||
* @param message The message to be posted. A bitwise copy of the message
|
||||
* will be delivered to the handler, after an unspecified time.
|
||||
*
|
||||
* @return True if the message could be posted, false otherwise. Note that
|
||||
* a return value of true only means that the message could successfully
|
||||
* be posted, not that it has reached the handler.
|
||||
*
|
||||
* @attention Note that the message queue must have been added to a worker
|
||||
* before a message can be posted.
|
||||
*/
|
||||
bool post(const Message& message) const;
|
||||
|
||||
/**
|
||||
* Adds the message queue to a particular worker.
|
||||
*
|
||||
* @param pWorker The worker the message queue should be added to.
|
||||
* Must remain valid until the message queue is removed
|
||||
* from it.
|
||||
*
|
||||
* @return True if the message queue could be added, otherwise false.
|
||||
*
|
||||
* @attention If the message queue is currently added to a worker, it
|
||||
* will first be removed from that worker.
|
||||
*/
|
||||
bool add_to_worker(Worker* pWorker);
|
||||
|
||||
/**
|
||||
* Removes the message queue from the worker it is currently added to.
|
||||
*
|
||||
* @return The worker the message queue was associated with, or NULL
|
||||
* if it was not associated with any.
|
||||
*/
|
||||
Worker* remove_from_worker();
|
||||
|
||||
private:
|
||||
MessageQueue(Handler* pHandler, int read_fd, int write_fd);
|
||||
|
||||
uint32_t handle_poll_events(int thread_id, uint32_t events);
|
||||
|
||||
static uint32_t poll_handler(MXS_POLL_DATA* pData, int thread_id, uint32_t events);
|
||||
|
||||
private:
|
||||
Handler& m_handler;
|
||||
int m_read_fd;
|
||||
int m_write_fd;
|
||||
Worker* m_pWorker;
|
||||
};
|
||||
|
||||
}
|
@ -26,22 +26,6 @@ struct mxs_worker;
|
||||
|
||||
#define MAX_EVENTS 1000
|
||||
|
||||
/**
|
||||
* A statistic identifier that can be returned by poll_get_stat
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
POLL_STAT_READ,
|
||||
POLL_STAT_WRITE,
|
||||
POLL_STAT_ERROR,
|
||||
POLL_STAT_HANGUP,
|
||||
POLL_STAT_ACCEPT,
|
||||
POLL_STAT_EVQ_LEN,
|
||||
POLL_STAT_EVQ_MAX,
|
||||
POLL_STAT_MAX_QTIME,
|
||||
POLL_STAT_MAX_EXECTIME
|
||||
} POLL_STAT;
|
||||
|
||||
enum poll_message
|
||||
{
|
||||
POLL_MSG_CLEAN_PERSISTENT = 0x01
|
||||
@ -58,7 +42,6 @@ void dShowThreads(DCB *dcb);
|
||||
void dShowEventQ(DCB *dcb);
|
||||
void dShowEventStats(DCB *dcb);
|
||||
|
||||
int64_t poll_get_stat(POLL_STAT stat);
|
||||
RESULTSET *eventTimesGetList();
|
||||
|
||||
MXS_END_DECLS
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
#include <maxscale/cppdefs.hh>
|
||||
#include <maxscale/routingworker.h>
|
||||
#include "worker.hh"
|
||||
#include <maxscale/worker.hh>
|
||||
#include "session.hh"
|
||||
|
||||
namespace maxscale
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,84 +0,0 @@
|
||||
#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: 2020-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/cppdefs.hh>
|
||||
|
||||
namespace maxscale
|
||||
{
|
||||
|
||||
class Worker;
|
||||
|
||||
/**
|
||||
* A WorkerTask represents a task to be performed by a Worker.
|
||||
*/
|
||||
class WorkerTask
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~WorkerTask();
|
||||
|
||||
/**
|
||||
* @brief Called in the context of a specific worker.
|
||||
*
|
||||
* @param worker The worker in whose context `execute` is called.
|
||||
*
|
||||
* @attention As the function is called by a worker, the body of `execute`
|
||||
* should execute quickly and not perform any blocking operations.
|
||||
*/
|
||||
virtual void execute(Worker& worker) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* A WorkerDisposableTask represents a task to be performed by a Worker.
|
||||
*
|
||||
* When the task has been executed, the instance will automatically be
|
||||
* deleted.
|
||||
*/
|
||||
class WorkerDisposableTask
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~WorkerDisposableTask();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
WorkerDisposableTask();
|
||||
|
||||
/**
|
||||
* @brief Called in the context of a specific worker.
|
||||
*
|
||||
* @param worker The worker in whose context `execute` is called.
|
||||
*
|
||||
* @attention As the function is called by a worker, the body of `execute`
|
||||
* should execute quickly and not perform any blocking operations.
|
||||
*/
|
||||
virtual void execute(Worker& worker) = 0;
|
||||
|
||||
private:
|
||||
friend class Worker;
|
||||
|
||||
void inc_ref();
|
||||
void dec_ref();
|
||||
|
||||
private:
|
||||
int32_t m_count;
|
||||
};
|
||||
|
||||
}
|
@ -11,7 +11,7 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include "internal/messagequeue.hh"
|
||||
#include <maxscale/messagequeue.hh>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "internal/poll.h"
|
||||
#include "internal/service.h"
|
||||
#include "internal/statistics.h"
|
||||
#include "internal/workertask.hh"
|
||||
|
||||
#define WORKER_ABSENT_ID -1
|
||||
|
||||
|
@ -43,7 +43,6 @@
|
||||
|
||||
#include "internal/monitor.h"
|
||||
#include "internal/poll.h"
|
||||
#include "internal/workertask.hh"
|
||||
#include "internal/routingworker.hh"
|
||||
|
||||
using maxscale::Semaphore;
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include "internal/filter.h"
|
||||
#include "internal/routingworker.hh"
|
||||
#include "internal/session.h"
|
||||
#include "internal/workertask.hh"
|
||||
|
||||
using std::string;
|
||||
using std::stringstream;
|
||||
|
@ -36,8 +36,8 @@
|
||||
|
||||
#include <maxscale/config.h>
|
||||
#include <maxscale/listener.h>
|
||||
#include <maxscale/messagequeue.hh>
|
||||
|
||||
#include "../internal/messagequeue.hh"
|
||||
#include "../internal/routingworker.hh"
|
||||
#include "../dcb.cc"
|
||||
#include "test_utils.h"
|
||||
|
@ -12,7 +12,8 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "../internal/worker.hh"
|
||||
#include <maxscale/worker.hh>
|
||||
#include "../internal/poll.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include "internal/worker.hh"
|
||||
#include <maxscale/worker.hh>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
@ -38,7 +38,6 @@
|
||||
#include "internal/poll.h"
|
||||
#include "internal/service.h"
|
||||
#include "internal/statistics.h"
|
||||
#include "internal/workertask.hh"
|
||||
|
||||
#define WORKER_ABSENT_ID -1
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
* Public License.
|
||||
*/
|
||||
|
||||
#include "internal/workertask.hh"
|
||||
#include <maxscale/workertask.hh>
|
||||
#include <maxscale/atomic.h>
|
||||
#include <maxscale/debug.h>
|
||||
|
||||
|
Reference in New Issue
Block a user