diff --git a/src/event/PollGroup.hxx b/src/event/Backend.hxx similarity index 77% rename from src/event/PollGroup.hxx rename to src/event/Backend.hxx index 104f1619d..e65eacd4a 100644 --- a/src/event/PollGroup.hxx +++ b/src/event/Backend.hxx @@ -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 diff --git a/src/event/BackendEvents.hxx b/src/event/BackendEvents.hxx index eeacb6d43..e47fd59c5 100644 --- a/src/event/BackendEvents.hxx +++ b/src/event/BackendEvents.hxx @@ -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 diff --git a/src/event/PollGroupEpoll.hxx b/src/event/EpollBackend.hxx similarity index 85% rename from src/event/PollGroupEpoll.hxx rename to src/event/EpollBackend.hxx index 48e53fd0f..df43509e6 100644 --- a/src/event/PollGroupEpoll.hxx +++ b/src/event/EpollBackend.hxx @@ -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 #include -class PollResultEpoll +class EpollBackendResult { - friend class PollGroupEpoll; + friend class EpollBackend; std::array 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); diff --git a/src/event/Loop.cxx b/src/event/Loop.cxx index d7f5af0db..01daf5d84 100644 --- a/src/event/Loop.cxx +++ b/src/event/Loop.cxx @@ -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); diff --git a/src/event/Loop.hxx b/src/event/Loop.hxx index 9f6f38308..a2b7eda81 100644 --- a/src/event/Loop.hxx +++ b/src/event/Loop.hxx @@ -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: /** diff --git a/src/event/PollGroupPoll.cxx b/src/event/PollBackend.cxx similarity index 85% rename from src/event/PollGroupPoll.cxx rename to src/event/PollBackend.cxx index a81b2ab2f..9a13ddbc3 100644 --- a/src/event/PollGroupPoll.cxx +++ b/src/event/PollBackend.cxx @@ -17,15 +17,15 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include "PollGroupPoll.hxx" +#include "PollBackend.hxx" #include -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); diff --git a/src/event/PollGroupPoll.hxx b/src/event/PollBackend.hxx similarity index 84% rename from src/event/PollGroupPoll.hxx rename to src/event/PollBackend.hxx index da31dc82a..629a6ad58 100644 --- a/src/event/PollGroupPoll.hxx +++ b/src/event/PollBackend.hxx @@ -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 -class PollGroupPoll +class PollBackend { struct Item { @@ -39,11 +39,11 @@ class PollGroupPoll std::vector poll_events; std::unordered_map 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; diff --git a/src/event/SocketEvent.hxx b/src/event/SocketEvent.hxx index 39d1c331c..17365b14a 100644 --- a/src/event/SocketEvent.hxx +++ b/src/event/SocketEvent.hxx @@ -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; diff --git a/src/event/PollGroupWinSelect.cxx b/src/event/WinSelectBackend.cxx similarity index 84% rename from src/event/PollGroupWinSelect.cxx rename to src/event/WinSelectBackend.cxx index 1a2b4365d..e8d7ab12d 100644 --- a/src/event/PollGroupWinSelect.cxx +++ b/src/event/WinSelectBackend.cxx @@ -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(); diff --git a/src/event/PollGroupWinSelect.hxx b/src/event/WinSelectBackend.hxx similarity index 90% rename from src/event/PollGroupWinSelect.hxx rename to src/event/WinSelectBackend.hxx index b89fabe34..b55478765 100644 --- a/src/event/PollGroupWinSelect.hxx +++ b/src/event/WinSelectBackend.hxx @@ -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; diff --git a/src/event/meson.build b/src/event/meson.build index 5331d67af..0218adc77 100644 --- a/src/event/meson.build +++ b/src/event/meson.build @@ -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(