Commit fec15c23 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook Github Bot

Add a BackendCb callback to support multiple types of backend operations (not limited to poll)

Summary: Add a BackendCb callback to support multiple types of backend operations (not limited to poll)

Reviewed By: danobi

Differential Revision: D19275105

fbshipit-source-id: 2eba28b429da4bc237e9c2c2a7e5d0505bd20961
parent d895d4ba
......@@ -49,14 +49,17 @@ IoUringBackend::IoUringBackend(size_t capacity, size_t maxSubmit, size_t maxGet)
timerEntry_ = &entries_[0];
timerEntry_->backend_ = this;
timerEntry_->backendCb_ = PollIoBackend::processTimerIoCb;
// build the free list - first entry is the timer entry
for (size_t i = 2; i < numEntries_; i++) {
entries_[i - 1].next_ = &entries_[i];
entries_[i - 1].backend_ = this;
entries_[i - 1].backendCb_ = PollIoBackend::processPollIoCb;
}
entries_[numEntries_ - 1].backend_ = this;
entries_[numEntries_ - 1].backendCb_ = PollIoBackend::processPollIoCb;
freeHead_ = &entries_[1];
// add the timer fd
......@@ -137,12 +140,7 @@ int IoUringBackend::getActiveEvents(WaitForEventsMode waitForEvents) {
while (cqe && (i < maxGet_)) {
i++;
IoSqe* sqe = reinterpret_cast<IoSqe*>(io_uring_cqe_get_data(cqe));
if (FOLLY_UNLIKELY(static_cast<PollIoBackend::IoCb*>(sqe) == timerEntry_)) {
// just set the flag here
processTimers_ = true;
} else {
processIoCb(sqe, cqe->res);
}
sqe->backendCb_(this, sqe, cqe->res);
::io_uring_cqe_seen(&ioRing_, cqe);
cqe = nullptr;
::io_uring_peek_cqe(&ioRing_, &cqe);
......
......@@ -75,7 +75,10 @@ class IoUringBackend : public PollIoBackend {
};
PollIoBackend::IoCb* allocNewIoCb() override {
return new IoSqe(this, false);
auto* ret = new IoSqe(this, false);
ret->backendCb_ = PollIoBackend::processPollIoCb;
return ret;
}
void cleanup();
......
......@@ -198,7 +198,7 @@ void PollIoBackend::releaseIoCb(PollIoBackend::IoCb* aioIoCb) {
}
}
void PollIoBackend::processIoCb(IoCb* ioCb, int64_t res) noexcept {
void PollIoBackend::processPollIo(IoCb* ioCb, int64_t res) noexcept {
auto* ev = ioCb->event_ ? (ioCb->event_->getEvent()) : nullptr;
if (ev) {
if (~event_ref_flags(ev) & EVLIST_INTERNAL) {
......
......@@ -49,15 +49,19 @@ class PollIoBackend : public EventBaseBackendBase {
protected:
enum class WaitForEventsMode { WAIT, DONT_WAIT };
struct IoCb;
struct IoCb
: public boost::intrusive::list_base_hook<
boost::intrusive::link_mode<boost::intrusive::auto_unlink>> {
using BackendCb = std::function<void(PollIoBackend*, IoCb*, int64_t)>;
explicit IoCb(PollIoBackend* backend, bool poolAlloc = true)
: backend_(backend), poolAlloc_(poolAlloc) {}
virtual ~IoCb() = default;
PollIoBackend* backend_;
BackendCb backendCb_;
const bool poolAlloc_;
IoCb* next_{nullptr}; // this is for the free list
Event* event_{nullptr};
......@@ -152,10 +156,24 @@ class PollIoBackend : public EventBaseBackendBase {
void addTimerEvent(Event& event, const struct timeval* timeout);
void removeTimerEvent(Event& event);
size_t processTimers();
FOLLY_ALWAYS_INLINE void setProcessTimers() {
processTimers_ = true;
}
size_t processActiveEvents();
void processIoCb(IoCb* ioCb, int64_t res) noexcept;
static void processPollIoCb(PollIoBackend* backend, IoCb* ioCb, int64_t res) {
backend->processPollIo(ioCb, res);
}
static void processTimerIoCb(
PollIoBackend* backend,
IoCb* /*unused*/,
int64_t /*unused*/) {
backend->setProcessTimers();
}
void processPollIo(IoCb* ioCb, int64_t res) noexcept;
IoCb* FOLLY_NULLABLE allocIoCb();
void releaseIoCb(IoCb* aioIoCb);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment