From 7e4fa8505f479c494b9e7bab361e4a11e1c579a5 Mon Sep 17 00:00:00 2001 From: Martin Sustrik Date: Thu, 16 Feb 2012 10:04:42 +0900 Subject: poller_base_t is used instead of poller_t Poller object is virtualised. You can access poller via its base class (poller_base_t) instead of using poller_t which was a typedef pointing to actual derived class. Signed-off-by: Martin Sustrik --- builds/msvc/libxs/libxs.vcxproj | 3 +-- builds/msvc/libxs/libxs.vcxproj.filters | 5 +---- src/Makefile.am | 1 - src/devpoll.hpp | 2 -- src/epoll.hpp | 2 -- src/io_object.hpp | 4 ++-- src/io_thread.cpp | 6 +++--- src/io_thread.hpp | 6 +++--- src/kqueue.hpp | 2 -- src/poll.hpp | 2 -- src/poller.hpp | 36 --------------------------------- src/poller_base.cpp | 24 ++++++++++++++++++++++ src/poller_base.hpp | 16 ++++++++++++++- src/reaper.cpp | 4 ++-- src/reaper.hpp | 4 ++-- src/select.hpp | 2 -- src/socket_base.cpp | 2 +- src/socket_base.hpp | 6 +++--- 18 files changed, 57 insertions(+), 70 deletions(-) delete mode 100644 src/poller.hpp diff --git a/builds/msvc/libxs/libxs.vcxproj b/builds/msvc/libxs/libxs.vcxproj index d438e8d..ff9bdee 100644 --- a/builds/msvc/libxs/libxs.vcxproj +++ b/builds/msvc/libxs/libxs.vcxproj @@ -206,7 +206,6 @@ - @@ -241,4 +240,4 @@ - \ No newline at end of file + diff --git a/builds/msvc/libxs/libxs.vcxproj.filters b/builds/msvc/libxs/libxs.vcxproj.filters index 78c16fa..5ca6843 100644 --- a/builds/msvc/libxs/libxs.vcxproj.filters +++ b/builds/msvc/libxs/libxs.vcxproj.filters @@ -304,9 +304,6 @@ Header Files - - Header Files - Header Files @@ -404,4 +401,4 @@ Header Files - \ No newline at end of file + diff --git a/src/Makefile.am b/src/Makefile.am index 65b4f3c..2c5341f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -47,7 +47,6 @@ libxs_la_SOURCES = \ pipe.hpp \ platform.hpp \ poll.hpp \ - poller.hpp \ poller_base.hpp \ pair.hpp \ pub.hpp \ diff --git a/src/devpoll.hpp b/src/devpoll.hpp index 8015f62..761152c 100644 --- a/src/devpoll.hpp +++ b/src/devpoll.hpp @@ -94,8 +94,6 @@ namespace xs const devpoll_t &operator = (const devpoll_t&); }; - typedef devpoll_t poller_t; - } #endif diff --git a/src/epoll.hpp b/src/epoll.hpp index 3745c77..e90c7e3 100644 --- a/src/epoll.hpp +++ b/src/epoll.hpp @@ -90,8 +90,6 @@ namespace xs const epoll_t &operator = (const epoll_t&); }; - typedef epoll_t poller_t; - } #endif diff --git a/src/io_object.hpp b/src/io_object.hpp index 4494a34..4bce10c 100644 --- a/src/io_object.hpp +++ b/src/io_object.hpp @@ -25,7 +25,7 @@ #include #include "stdint.hpp" -#include "poller.hpp" +#include "poller_base.hpp" #include "i_poll_events.hpp" namespace xs @@ -68,7 +68,7 @@ namespace xs private: - poller_t *poller; + poller_base_t *poller; io_object_t (const io_object_t&); const io_object_t &operator = (const io_object_t&); diff --git a/src/io_thread.cpp b/src/io_thread.cpp index 75bca4f..c1f5849 100644 --- a/src/io_thread.cpp +++ b/src/io_thread.cpp @@ -29,8 +29,8 @@ xs::io_thread_t::io_thread_t (ctx_t *ctx_, uint32_t tid_) : object_t (ctx_, tid_) { - poller = new (std::nothrow) poller_t; - alloc_assert (poller); + poller = poller_base_t::create (); + xs_assert (poller); mailbox_handle = poller->add_fd (mailbox.get_fd (), this); poller->set_pollin (mailbox_handle); @@ -95,7 +95,7 @@ void xs::io_thread_t::timer_event (int id_) xs_assert (false); } -xs::poller_t *xs::io_thread_t::get_poller () +xs::poller_base_t *xs::io_thread_t::get_poller () { xs_assert (poller); return poller; diff --git a/src/io_thread.hpp b/src/io_thread.hpp index 0acb60d..744eec5 100644 --- a/src/io_thread.hpp +++ b/src/io_thread.hpp @@ -26,7 +26,7 @@ #include "stdint.hpp" #include "object.hpp" -#include "poller.hpp" +#include "poller_base.hpp" #include "i_poll_events.hpp" #include "mailbox.hpp" @@ -63,7 +63,7 @@ namespace xs void timer_event (int id_); // Used by io_objects to retrieve the assciated poller object. - poller_t *get_poller (); + poller_base_t *get_poller (); // Command handlers. void process_stop (); @@ -80,7 +80,7 @@ namespace xs handle_t mailbox_handle; // I/O multiplexing is performed using a poller object. - poller_t *poller; + poller_base_t *poller; io_thread_t (const io_thread_t&); const io_thread_t &operator = (const io_thread_t&); diff --git a/src/kqueue.hpp b/src/kqueue.hpp index 02388c1..436dadd 100644 --- a/src/kqueue.hpp +++ b/src/kqueue.hpp @@ -95,8 +95,6 @@ namespace xs const kqueue_t &operator = (const kqueue_t&); }; - typedef kqueue_t poller_t; - } #endif diff --git a/src/poll.hpp b/src/poll.hpp index cdeb75b..7b9b024 100644 --- a/src/poll.hpp +++ b/src/poll.hpp @@ -94,8 +94,6 @@ namespace xs const poll_t &operator = (const poll_t&); }; - typedef poll_t poller_t; - } #endif diff --git a/src/poller.hpp b/src/poller.hpp deleted file mode 100644 index eff2e5e..0000000 --- a/src/poller.hpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (c) 2010-2012 250bpm s.r.o. - Copyright (c) 2007-2009 iMatix Corporation - Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file - - This file is part of Crossroads project. - - Crossroads is free software; you can redistribute it and/or modify it under - the terms of the GNU Lesser General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - Crossroads is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . -*/ - -#ifndef __XS_POLLER_HPP_INCLUDED__ -#define __XS_POLLER_HPP_INCLUDED__ - -namespace xs -{ - typedef void* handle_t; -} - -#include "devpoll.hpp" -#include "epoll.hpp" -#include "kqueue.hpp" -#include "poll.hpp" -#include "select.hpp" - -#endif diff --git a/src/poller_base.cpp b/src/poller_base.cpp index 7c8ddfd..5fe3a4f 100644 --- a/src/poller_base.cpp +++ b/src/poller_base.cpp @@ -22,6 +22,30 @@ #include "i_poll_events.hpp" #include "err.hpp" +#include "select.hpp" +#include "poll.hpp" +#include "epoll.hpp" +#include "devpoll.hpp" +#include "kqueue.hpp" + +xs::poller_base_t *xs::poller_base_t::create () +{ + poller_base_t *result; +#if defined XS_HAVE_SELECT + result = new (std::nothrow) select_t; +#elif defined XS_HAVE_POLL + result = new (std::nothrow) poll_t; +#elif defined XS_HAVE_EPOLL + result = new (std::nothrow) epoll_t; +#elif defined XS_HAVE_DEVPOLL + result = new (std::nothrow) devpoll_t; +#elif defined XS_HAVE_KQUEUE + result = new (std::nothrow) kqueue_t; +#endif + alloc_assert (result); + return result; +} + xs::poller_base_t::poller_base_t () { } diff --git a/src/poller_base.hpp b/src/poller_base.hpp index 99a77b9..8d9ed16 100644 --- a/src/poller_base.hpp +++ b/src/poller_base.hpp @@ -23,6 +23,7 @@ #include +#include "fd.hpp" #include "clock.hpp" #include "atomic_counter.hpp" @@ -37,13 +38,24 @@ namespace xs { public: - poller_base_t (); + // Create optimal poller mechanism for this environment. + static poller_base_t *create (); + virtual ~poller_base_t (); // Returns load of the poller. Note that this function can be // invoked from a different thread! int get_load (); + virtual handle_t add_fd (fd_t fd_, xs::i_poll_events *events_) = 0; + virtual void rm_fd (handle_t handle_) = 0; + virtual void set_pollin (handle_t handle_) = 0; + virtual void reset_pollin (handle_t handle_) = 0; + virtual void set_pollout (handle_t handle_) = 0; + virtual void reset_pollout (handle_t handle_) = 0; + virtual void start () = 0; + virtual void stop () = 0; + // Add a timeout to expire in timeout_ milliseconds. After the // expiration timer_event on sink_ object will be called with // argument set to id_. @@ -54,6 +66,8 @@ namespace xs protected: + poller_base_t (); + // Called by individual poller implementations to manage the load. void adjust_load (int amount_); diff --git a/src/reaper.cpp b/src/reaper.cpp index 7e38b73..c9a5961 100644 --- a/src/reaper.cpp +++ b/src/reaper.cpp @@ -27,8 +27,8 @@ xs::reaper_t::reaper_t (class ctx_t *ctx_, uint32_t tid_) : sockets (0), terminating (false) { - poller = new (std::nothrow) poller_t; - alloc_assert (poller); + poller = poller_base_t::create (); + xs_assert (poller); mailbox_handle = poller->add_fd (mailbox.get_fd (), this); poller->set_pollin (mailbox_handle); diff --git a/src/reaper.hpp b/src/reaper.hpp index 3310145..805916f 100644 --- a/src/reaper.hpp +++ b/src/reaper.hpp @@ -23,7 +23,7 @@ #include "object.hpp" #include "mailbox.hpp" -#include "poller.hpp" +#include "poller_base.hpp" #include "i_poll_events.hpp" namespace xs @@ -63,7 +63,7 @@ namespace xs handle_t mailbox_handle; // I/O multiplexing is performed using a poller object. - poller_t *poller; + poller_base_t *poller; // Number of sockets being reaped at the moment. int sockets; diff --git a/src/select.hpp b/src/select.hpp index 3686507..5279402 100644 --- a/src/select.hpp +++ b/src/select.hpp @@ -115,8 +115,6 @@ namespace xs const select_t &operator = (const select_t&); }; - typedef select_t poller_t; - } #endif diff --git a/src/socket_base.cpp b/src/socket_base.cpp index 3854dc2..94b555b 100644 --- a/src/socket_base.cpp +++ b/src/socket_base.cpp @@ -641,7 +641,7 @@ bool xs::socket_base_t::has_out () return xhas_out (); } -void xs::socket_base_t::start_reaping (poller_t *poller_) +void xs::socket_base_t::start_reaping (poller_base_t *poller_) { // Plug the socket to the reaper thread. poller = poller_; diff --git a/src/socket_base.hpp b/src/socket_base.hpp index 614d3d0..250215b 100644 --- a/src/socket_base.hpp +++ b/src/socket_base.hpp @@ -28,7 +28,7 @@ #include "own.hpp" #include "array.hpp" #include "stdint.hpp" -#include "poller.hpp" +#include "poller_base.hpp" #include "atomic_counter.hpp" #include "i_poll_events.hpp" #include "mailbox.hpp" @@ -82,7 +82,7 @@ namespace xs // Using this function reaper thread ask the socket to regiter with // its poller. - void start_reaping (poller_t *poller_); + void start_reaping (poller_base_t *poller_); // i_poll_events implementation. This interface is used when socket // is handled by the poller in the reaper thread. @@ -180,7 +180,7 @@ namespace xs pipes_t pipes; // Reaper's poller and handle of this socket within it. - poller_t *poller; + poller_base_t *poller; handle_t handle; // Timestamp of when commands were processed the last time. -- cgit v1.2.3