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.
*/
#ifndef MPD_EVENT_POLLGROUP_HXX
#define MPD_EVENT_POLLGROUP_HXX
#ifndef EVENT_BACKEND_HXX
#define EVENT_BACKEND_HXX
#include "event/Features.h"
#ifdef _WIN32
#include "PollGroupWinSelect.hxx"
typedef PollGroupWinSelect PollGroup;
#include "WinSelectBackend.hxx"
using EventPollBackend = WinSelectBackend;
#elif defined(USE_EPOLL)
#include "PollGroupEpoll.hxx"
typedef PollGroupEpoll PollGroup;
#include "EpollBackend.hxx"
using EventPollBackend = EpollBackend;
#else
#include "PollGroupPoll.hxx"
typedef PollGroupPoll PollGroup;
#include "PollBackend.hxx"
using EventPollBackend = PollBackend;
#endif

View File

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

View File

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

View File

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

View File

@ -21,7 +21,7 @@
#define MPD_EVENT_LOOP_HXX
#include "Chrono.hxx"
#include "PollGroup.hxx"
#include "Backend.hxx"
#include "SocketEvent.hxx"
#include "event/Features.h"
#include "util/Compiler.h"
@ -130,7 +130,7 @@ class EventLoop final
/**
* 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;
@ -148,7 +148,7 @@ class EventLoop final
bool uring_initialized = false;
#endif
PollGroup poll_group;
EventPollBackend poll_backend;
public:
/**

View File

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

View File

@ -17,8 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_EVENT_POLLGROUP_POLL_HXX
#define MPD_EVENT_POLLGROUP_POLL_HXX
#ifndef EVENT_POLL_BACKEND_HXX
#define EVENT_POLL_BACKEND_HXX
#include "PollResultGeneric.hxx"
@ -28,7 +28,7 @@
#include <sys/poll.h>
class PollGroupPoll
class PollBackend
{
struct Item
{
@ -39,11 +39,11 @@ class PollGroupPoll
std::vector<pollfd> poll_events;
std::unordered_map<int, Item> items;
PollGroupPoll(PollGroupPoll &) = delete;
PollGroupPoll &operator=(PollGroupPoll &) = delete;
PollBackend(PollBackend &) = delete;
PollBackend &operator=(PollBackend &) = delete;
public:
PollGroupPoll() noexcept;
~PollGroupPoll() noexcept;
PollBackend() noexcept;
~PollBackend() noexcept;
PollResultGeneric ReadEvents(int timeout_ms) 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
* as thread-safe.
*/
class SocketEvent final : IntrusiveListHook, public PollBackendEvents {
class SocketEvent final : IntrusiveListHook, public EventPollBackendEvents {
friend class EventLoop;
friend class IntrusiveList<SocketEvent>;

View File

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

View File

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

View File

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