event/PollGroup: rename to PollBackend

This commit is contained in:
Max Kellermann 2020-10-19 14:14:32 +02:00
parent c18e00daa4
commit 8348a1ec8f
11 changed files with 63 additions and 63 deletions

View File

@ -17,25 +17,25 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_EVENT_POLLGROUP_HXX #ifndef EVENT_BACKEND_HXX
#define MPD_EVENT_POLLGROUP_HXX #define EVENT_BACKEND_HXX
#include "event/Features.h" #include "event/Features.h"
#ifdef _WIN32 #ifdef _WIN32
#include "PollGroupWinSelect.hxx" #include "WinSelectBackend.hxx"
typedef PollGroupWinSelect PollGroup; using EventPollBackend = WinSelectBackend;
#elif defined(USE_EPOLL) #elif defined(USE_EPOLL)
#include "PollGroupEpoll.hxx" #include "EpollBackend.hxx"
typedef PollGroupEpoll PollGroup; using EventPollBackend = EpollBackend;
#else #else
#include "PollGroupPoll.hxx" #include "PollBackend.hxx"
typedef PollGroupPoll PollGroup; using EventPollBackend = PollBackend;
#endif #endif

View File

@ -25,17 +25,17 @@
#ifdef _WIN32 #ifdef _WIN32
#include "WinSelectEvents.hxx" #include "WinSelectEvents.hxx"
using PollBackendEvents = WinSelectEvents; using EventPollBackendEvents = WinSelectEvents;
#elif defined(USE_EPOLL) #elif defined(USE_EPOLL)
#include "EpollEvents.hxx" #include "EpollEvents.hxx"
using PollBackendEvents = EpollEvents; using EventPollBackendEvents = EpollEvents;
#else #else
#include "PollEvents.hxx" #include "PollEvents.hxx"
using PollBackendEvents = PollEvents; using EventPollBackendEvents = PollEvents;
#endif #endif

View File

@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_EVENT_POLLGROUP_EPOLL_HXX #ifndef EVENT_EPOLL_BACKEND_HXX
#define MPD_EVENT_POLLGROUP_EPOLL_HXX #define EVENT_EPOLL_BACKEND_HXX
#include "util/Compiler.h" #include "util/Compiler.h"
#include "system/EpollFD.hxx" #include "system/EpollFD.hxx"
@ -26,9 +26,9 @@
#include <array> #include <array>
#include <algorithm> #include <algorithm>
class PollResultEpoll class EpollBackendResult
{ {
friend class PollGroupEpoll; friend class EpollBackend;
std::array<epoll_event, 16> events; std::array<epoll_event, 16> events;
size_t n_events = 0; size_t n_events = 0;
@ -47,17 +47,17 @@ public:
} }
}; };
class PollGroupEpoll class EpollBackend
{ {
EpollFD epoll; EpollFD epoll;
PollGroupEpoll(PollGroupEpoll &) = delete; EpollBackend(EpollBackend &) = delete;
PollGroupEpoll &operator=(PollGroupEpoll &) = delete; EpollBackend &operator=(EpollBackend &) = delete;
public: public:
PollGroupEpoll() = default; EpollBackend() = default;
auto ReadEvents(int timeout_ms) noexcept { auto ReadEvents(int timeout_ms) noexcept {
PollResultEpoll result; EpollBackendResult result;
int ret = epoll.Wait(result.events.data(), result.events.size(), int ret = epoll.Wait(result.events.data(), result.events.size(),
timeout_ms); timeout_ms);
result.n_events = std::max(0, ret); result.n_events = std::max(0, ret);

View File

@ -109,7 +109,7 @@ EventLoop::AbandonFD(int _fd) noexcept
assert(!IsAlive() || IsInside()); assert(!IsAlive() || IsInside());
#endif #endif
return poll_group.Abandon(_fd); return poll_backend.Abandon(_fd);
} }
bool bool
@ -120,7 +120,7 @@ EventLoop::AddFD(int fd, unsigned events, SocketEvent &event) noexcept
#endif #endif
assert(events != 0); assert(events != 0);
if (!poll_group.Add(fd, events, &event)) if (!poll_backend.Add(fd, events, &event))
return false; return false;
sockets.push_back(event); sockets.push_back(event);
@ -135,7 +135,7 @@ EventLoop::ModifyFD(int fd, unsigned events, SocketEvent &event) noexcept
#endif #endif
assert(events != 0); assert(events != 0);
return poll_group.Modify(fd, events, &event); return poll_backend.Modify(fd, events, &event);
} }
bool bool
@ -146,7 +146,7 @@ EventLoop::RemoveFD(int fd, SocketEvent &event) noexcept
#endif #endif
event.unlink(); event.unlink();
return poll_group.Remove(fd); return poll_backend.Remove(fd);
} }
void void
@ -220,7 +220,7 @@ inline bool
EventLoop::Wait(Event::Duration timeout) noexcept EventLoop::Wait(Event::Duration timeout) noexcept
{ {
const auto poll_result = const auto poll_result =
poll_group.ReadEvents(ExportTimeoutMS(timeout)); poll_backend.ReadEvents(ExportTimeoutMS(timeout));
for (size_t i = 0; i < poll_result.GetSize(); ++i) { for (size_t i = 0; i < poll_result.GetSize(); ++i) {
auto &socket_event = *(SocketEvent *)poll_result.GetObject(i); auto &socket_event = *(SocketEvent *)poll_result.GetObject(i);

View File

@ -21,7 +21,7 @@
#define MPD_EVENT_LOOP_HXX #define MPD_EVENT_LOOP_HXX
#include "Chrono.hxx" #include "Chrono.hxx"
#include "PollGroup.hxx" #include "Backend.hxx"
#include "SocketEvent.hxx" #include "SocketEvent.hxx"
#include "event/Features.h" #include "event/Features.h"
#include "util/Compiler.h" #include "util/Compiler.h"
@ -130,7 +130,7 @@ class EventLoop final
/** /**
* True when the object has been modified and another check is * True when the object has been modified and another check is
* necessary before going to sleep via PollGroup::ReadEvents(). * necessary before going to sleep via EventPollBackend::ReadEvents().
*/ */
bool again; bool again;
@ -148,7 +148,7 @@ class EventLoop final
bool uring_initialized = false; bool uring_initialized = false;
#endif #endif
PollGroup poll_group; EventPollBackend poll_backend;
public: public:
/** /**

View File

@ -17,15 +17,15 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "PollGroupPoll.hxx" #include "PollBackend.hxx"
#include <cassert> #include <cassert>
PollGroupPoll::PollGroupPoll() noexcept = default; PollBackend::PollBackend() noexcept = default;
PollGroupPoll::~PollGroupPoll() noexcept = default; PollBackend::~PollBackend() noexcept = default;
bool bool
PollGroupPoll::Add(int fd, unsigned events, void *obj) noexcept PollBackend::Add(int fd, unsigned events, void *obj) noexcept
{ {
assert(items.find(fd) == items.end()); assert(items.find(fd) == items.end());
@ -42,7 +42,7 @@ PollGroupPoll::Add(int fd, unsigned events, void *obj) noexcept
} }
bool bool
PollGroupPoll::Modify(int fd, unsigned events, void *obj) noexcept PollBackend::Modify(int fd, unsigned events, void *obj) noexcept
{ {
auto item_iter = items.find(fd); auto item_iter = items.find(fd);
assert(item_iter != items.end()); assert(item_iter != items.end());
@ -55,7 +55,7 @@ PollGroupPoll::Modify(int fd, unsigned events, void *obj) noexcept
} }
bool bool
PollGroupPoll::Remove(int fd) noexcept PollBackend::Remove(int fd) noexcept
{ {
auto item_iter = items.find(fd); auto item_iter = items.find(fd);
assert(item_iter != items.end()); assert(item_iter != items.end());
@ -72,7 +72,7 @@ PollGroupPoll::Remove(int fd) noexcept
} }
PollResultGeneric PollResultGeneric
PollGroupPoll::ReadEvents(int timeout_ms) noexcept PollBackend::ReadEvents(int timeout_ms) noexcept
{ {
int n = poll(poll_events.empty() ? nullptr : &poll_events[0], int n = poll(poll_events.empty() ? nullptr : &poll_events[0],
poll_events.size(), timeout_ms); poll_events.size(), timeout_ms);

View File

@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_EVENT_POLLGROUP_POLL_HXX #ifndef EVENT_POLL_BACKEND_HXX
#define MPD_EVENT_POLLGROUP_POLL_HXX #define EVENT_POLL_BACKEND_HXX
#include "PollResultGeneric.hxx" #include "PollResultGeneric.hxx"
@ -28,7 +28,7 @@
#include <sys/poll.h> #include <sys/poll.h>
class PollGroupPoll class PollBackend
{ {
struct Item struct Item
{ {
@ -39,11 +39,11 @@ class PollGroupPoll
std::vector<pollfd> poll_events; std::vector<pollfd> poll_events;
std::unordered_map<int, Item> items; std::unordered_map<int, Item> items;
PollGroupPoll(PollGroupPoll &) = delete; PollBackend(PollBackend &) = delete;
PollGroupPoll &operator=(PollGroupPoll &) = delete; PollBackend &operator=(PollBackend &) = delete;
public: public:
PollGroupPoll() noexcept; PollBackend() noexcept;
~PollGroupPoll() noexcept; ~PollBackend() noexcept;
PollResultGeneric ReadEvents(int timeout_ms) noexcept; PollResultGeneric ReadEvents(int timeout_ms) noexcept;
bool Add(int fd, unsigned events, void *obj) noexcept; bool Add(int fd, unsigned events, void *obj) noexcept;

View File

@ -44,7 +44,7 @@ class EventLoop;
* thread that runs the #EventLoop, except where explicitly documented * thread that runs the #EventLoop, except where explicitly documented
* as thread-safe. * as thread-safe.
*/ */
class SocketEvent final : IntrusiveListHook, public PollBackendEvents { class SocketEvent final : IntrusiveListHook, public EventPollBackendEvents {
friend class EventLoop; friend class EventLoop;
friend class IntrusiveList<SocketEvent>; friend class IntrusiveList<SocketEvent>;

View File

@ -17,7 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "PollGroupWinSelect.hxx" #include "WinSelectBackend.hxx"
#include "WinSelectEvents.hxx" #include "WinSelectEvents.hxx"
static constexpr int EVENT_READ = 0; static constexpr int EVENT_READ = 0;
@ -29,12 +29,12 @@ bool HasEvent(unsigned events, int event_id) noexcept
return (events & (1 << event_id)) != 0; return (events & (1 << event_id)) != 0;
} }
PollGroupWinSelect::PollGroupWinSelect() noexcept = default; WinSelectBackend::WinSelectBackend() noexcept = default;
PollGroupWinSelect::~PollGroupWinSelect() noexcept = default; WinSelectBackend::~WinSelectBackend() noexcept = default;
bool bool
PollGroupWinSelect::CanModify(PollGroupWinSelect::Item &item, WinSelectBackend::CanModify(WinSelectBackend::Item &item,
unsigned events, int event_id) const noexcept unsigned events, int event_id) const noexcept
{ {
if (item.index[event_id] < 0 && HasEvent(events, event_id)) if (item.index[event_id] < 0 && HasEvent(events, event_id))
return !event_set[event_id].IsFull(); return !event_set[event_id].IsFull();
@ -42,8 +42,8 @@ PollGroupWinSelect::CanModify(PollGroupWinSelect::Item &item,
} }
void void
PollGroupWinSelect::Modify(PollGroupWinSelect::Item &item, SOCKET fd, WinSelectBackend::Modify(WinSelectBackend::Item &item, SOCKET fd,
unsigned events, int event_id) noexcept unsigned events, int event_id) noexcept
{ {
int index = item.index[event_id]; int index = item.index[event_id];
auto &set = event_set[event_id]; auto &set = event_set[event_id];
@ -61,7 +61,7 @@ PollGroupWinSelect::Modify(PollGroupWinSelect::Item &item, SOCKET fd,
} }
bool bool
PollGroupWinSelect::Add(SOCKET fd, unsigned events, void *obj) noexcept WinSelectBackend::Add(SOCKET fd, unsigned events, void *obj) noexcept
{ {
assert(items.find(fd) == items.end()); assert(items.find(fd) == items.end());
auto &item = items[fd]; auto &item = items[fd];
@ -86,7 +86,7 @@ PollGroupWinSelect::Add(SOCKET fd, unsigned events, void *obj) noexcept
} }
bool bool
PollGroupWinSelect::Modify(SOCKET fd, unsigned events, void *obj) noexcept WinSelectBackend::Modify(SOCKET fd, unsigned events, void *obj) noexcept
{ {
auto item_iter = items.find(fd); auto item_iter = items.find(fd);
assert(item_iter != items.end()); assert(item_iter != items.end());
@ -104,7 +104,7 @@ PollGroupWinSelect::Modify(SOCKET fd, unsigned events, void *obj) noexcept
} }
bool bool
PollGroupWinSelect::Remove(SOCKET fd) noexcept WinSelectBackend::Remove(SOCKET fd) noexcept
{ {
auto item_iter = items.find(fd); auto item_iter = items.find(fd);
assert(item_iter != items.end()); assert(item_iter != items.end());
@ -117,7 +117,7 @@ PollGroupWinSelect::Remove(SOCKET fd) noexcept
} }
PollResultGeneric PollResultGeneric
PollGroupWinSelect::ReadEvents(int timeout_ms) noexcept WinSelectBackend::ReadEvents(int timeout_ms) noexcept
{ {
bool use_sleep = event_set[EVENT_READ].IsEmpty() && bool use_sleep = event_set[EVENT_READ].IsEmpty() &&
event_set[EVENT_WRITE].IsEmpty(); event_set[EVENT_WRITE].IsEmpty();

View File

@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#ifndef MPD_EVENT_POLLGROUP_WINSELECT_HXX #ifndef EVENT_WINSELECT_BACKEND_HXX
#define MPD_EVENT_POLLGROUP_WINSELECT_HXX #define EVENT_WINSELECT_BACKEND_HXX
#include "PollResultGeneric.hxx" #include "PollResultGeneric.hxx"
@ -87,7 +87,7 @@ public:
} }
}; };
class PollGroupWinSelect class WinSelectBackend
{ {
struct Item struct Item
{ {
@ -104,11 +104,11 @@ class PollGroupWinSelect
void Modify(Item &item, SOCKET fd, unsigned events, void Modify(Item &item, SOCKET fd, unsigned events,
int event_id) noexcept; int event_id) noexcept;
PollGroupWinSelect(PollGroupWinSelect &) = delete; WinSelectBackend(WinSelectBackend &) = delete;
PollGroupWinSelect &operator=(PollGroupWinSelect &) = delete; WinSelectBackend &operator=(WinSelectBackend &) = delete;
public: public:
PollGroupWinSelect() noexcept; WinSelectBackend() noexcept;
~PollGroupWinSelect() noexcept; ~WinSelectBackend() noexcept;
PollResultGeneric ReadEvents(int timeout_ms) noexcept; PollResultGeneric ReadEvents(int timeout_ms) noexcept;
bool Add(SOCKET fd, unsigned events, void *obj) noexcept; bool Add(SOCKET fd, unsigned events, void *obj) noexcept;

View File

@ -12,11 +12,11 @@ if uring_dep.found()
endif endif
if is_windows if is_windows
event_sources += 'PollGroupWinSelect.cxx' event_sources += 'WinSelectBackend.cxx'
elif is_linux and get_option('epoll') elif is_linux and get_option('epoll')
# epoll support is header-only # epoll support is header-only
else else
event_sources += 'PollGroupPoll.cxx' event_sources += 'PollBackend.cxx'
endif endif
event = static_library( event = static_library(