From 242a4a9abe1e1113b5eb39aa751aa054f696d7be Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 27 Sep 2019 22:35:14 +0300 Subject: [PATCH] Additional adjustments for Poller --- source/io/eventdispatcher.cpp | 4 ++-- source/io/poll.cpp | 11 +++++------ source/io/poll.h | 20 +++++++++++--------- source/io/unix/poll.cpp | 4 ++-- source/io/windows/poll.cpp | 6 +++--- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/source/io/eventdispatcher.cpp b/source/io/eventdispatcher.cpp index 550043f..f98474c 100644 --- a/source/io/eventdispatcher.cpp +++ b/source/io/eventdispatcher.cpp @@ -63,8 +63,8 @@ void EventDispatcher::tick(const Time::Timer &timer) void EventDispatcher::dispatch() { - const vector &result = poller.get_result(); - for(vector::const_iterator i=result.begin(); i!=result.end(); ++i) + const vector &result = poller.get_result(); + for(vector::const_iterator i=result.begin(); i!=result.end(); ++i) i->object->event(i->events); } diff --git a/source/io/poll.cpp b/source/io/poll.cpp index 2e33502..a5d2d02 100644 --- a/source/io/poll.cpp +++ b/source/io/poll.cpp @@ -25,7 +25,7 @@ void Poller::set_object(EventObject &obj, PollEvent ev) if(ev) obj.get_event_handle(); - for(vector::iterator i=objects.begin(); i!=objects.end(); ++i) + for(vector::iterator i=objects.begin(); i!=objects.end(); ++i) if(i->object==&obj) { if(ev) @@ -48,16 +48,16 @@ void Poller::set_object(EventObject &obj, PollEvent ev) throw logic_error("Maximum number of wait objects reached"); #endif - objects.push_back(Slot(&obj, ev)); + objects.push_back(PolledObject(&obj, ev)); objs_changed = true; } -int Poller::poll() +unsigned Poller::poll() { return do_poll(-1); } -int Poller::poll(const Time::TimeDelta &timeout) +unsigned Poller::poll(const Time::TimeDelta &timeout) { if(timeout(timeout/Time::msec)); } -int Poller::do_poll(int timeout) +unsigned Poller::do_poll(int timeout) { if(objs_changed || events_changed) { @@ -82,7 +82,6 @@ int Poller::do_poll(int timeout) } - PollEvent platform_poll(EventObject &, PollEvent, int); PollEvent poll(EventObject &obj, PollEvent pe) diff --git a/source/io/poll.h b/source/io/poll.h index fdb68c5..40c15a7 100644 --- a/source/io/poll.h +++ b/source/io/poll.h @@ -35,37 +35,39 @@ inline PollEvent operator~(PollEvent e) class Poller: private NonCopyable { public: - struct Slot + struct PolledObject { EventObject *object; PollEvent events; - Slot(EventObject *o, PollEvent e): object(o), events(e) { } + PolledObject(EventObject *o, PollEvent e): object(o), events(e) { } }; - typedef std::vector SlotList DEPRECATED; + typedef PolledObject Slot DEPRECATED; + + typedef std::vector SlotList DEPRECATED; private: struct Private; - std::vector objects; + std::vector objects; Private *priv; bool events_changed; bool objs_changed; - std::vector poll_result; + std::vector poll_result; public: Poller(); ~Poller(); void set_object(EventObject &, PollEvent); - int poll(); - int poll(const Time::TimeDelta &); + unsigned poll(); + unsigned poll(const Time::TimeDelta &); private: void rebuild_array(); - int do_poll(int); + unsigned do_poll(int); void platform_poll(int); public: - const std::vector &get_result() const { return poll_result; } + const std::vector &get_result() const { return poll_result; } }; PollEvent poll(EventObject &, PollEvent); diff --git a/source/io/unix/poll.cpp b/source/io/unix/poll.cpp index 0fb9d22..7df113e 100644 --- a/source/io/unix/poll.cpp +++ b/source/io/unix/poll.cpp @@ -62,7 +62,7 @@ void Poller::rebuild_array() priv->pfd.clear(); priv->pfd.reserve(objects.size()); - for(vector::const_iterator i=objects.begin(); i!=objects.end(); ++i) + for(vector::const_iterator i=objects.begin(); i!=objects.end(); ++i) { pollfd p; p.fd = *i->object->get_event_handle(); @@ -91,7 +91,7 @@ void Poller::platform_poll(int timeout) for(unsigned i=0; (i0); ++i) if(priv->pfd[i].revents) { - poll_result.push_back(Slot(objects[i].object, poll_event_from_sys(priv->pfd[i].revents))); + poll_result.push_back(PolledObject(objects[i].object, poll_event_from_sys(priv->pfd[i].revents))); --ret; } } diff --git a/source/io/windows/poll.cpp b/source/io/windows/poll.cpp index b3ee8ec..7aafc6e 100644 --- a/source/io/windows/poll.cpp +++ b/source/io/windows/poll.cpp @@ -18,7 +18,7 @@ void Poller::rebuild_array() priv->handles.clear(); priv->handles.reserve(objects.size()); - for(vector::const_iterator i=objects.begin(); i!=objects.end(); ++i) + for(vector::const_iterator i=objects.begin(); i!=objects.end(); ++i) priv->handles.push_back(*i->object->get_event_handle()); } @@ -30,8 +30,8 @@ void Poller::platform_poll(int timeout) DWORD ret = WaitForMultipleObjects(priv->handles.size(), &priv->handles.front(), false, timeout); if(/*ret>=WAIT_OBJECT_0 &&*/ rethandles.size()) { - const Slot &slot = objects[ret-WAIT_OBJECT_0]; - poll_result.push_back(slot); + const PolledObject &obj = objects[ret-WAIT_OBJECT_0]; + poll_result.push_back(obj); } else if(ret==WAIT_FAILED) throw system_error("WaitForMultipleObjects"); -- 2.45.2