diff --git a/hpx/util/io_service_pool.hpp b/hpx/util/io_service_pool.hpp index 3c28917675fd..afcd639d97b7 100644 --- a/hpx/util/io_service_pool.hpp +++ b/hpx/util/io_service_pool.hpp @@ -14,12 +14,12 @@ #include #include +#include #include #include #include #include -#include /////////////////////////////////////////////////////////////////////////////// namespace hpx { namespace util @@ -89,17 +89,32 @@ namespace hpx { namespace util void clear_locked(); private: - typedef boost::shared_ptr io_service_ptr; - typedef boost::shared_ptr work_ptr; + typedef std::unique_ptr io_service_ptr; +#if (defined(HPX_GCC_VERSION) && HPX_GCC_VERSION < 40700) + typedef std::unique_ptr work_type; +#else + typedef boost::asio::io_service::work work_type; +#endif + + BOOST_FORCEINLINE work_type initialize_work(boost::asio::io_service& io_service) + { + return work_type( +#if (defined(HPX_GCC_VERSION) && HPX_GCC_VERSION < 40700) + new boost::asio::io_service::work(io_service) +#else + io_service +#endif + ); + } boost::mutex mtx_; /// The pool of io_services. std::vector io_services_; - std::vector > threads_; + std::vector threads_; /// The work that keeps the io_services running. - std::vector work_; + std::vector work_; /// The next io_service to use for a connection. std::size_t next_io_service_; diff --git a/src/util/io_service_pool.cpp b/src/util/io_service_pool.cpp index 563f0aa2da50..c0999095c72f 100644 --- a/src/util/io_service_pool.cpp +++ b/src/util/io_service_pool.cpp @@ -44,10 +44,8 @@ namespace hpx { namespace util // will not exit until they are explicitly stopped. for (std::size_t i = 0; i < pool_size; ++i) { - io_service_ptr io_service(new boost::asio::io_service); - work_ptr work(new boost::asio::io_service::work(*io_service)); - io_services_.push_back(io_service); - work_.push_back(work); + io_services_.emplace_back(new boost::asio::io_service); + work_.emplace_back(initialize_work(*io_services_[i])); } } @@ -62,10 +60,8 @@ namespace hpx { namespace util { for (std::size_t i = 0; i < pool_size_; ++i) { - io_service_ptr io_service(new boost::asio::io_service); - work_ptr work(new boost::asio::io_service::work(*io_service)); - io_services_.push_back(io_service); - work_.push_back(work); + io_services_.emplace_back(new boost::asio::io_service); + work_.emplace_back(initialize_work(*io_services_[i])); } } @@ -115,18 +111,16 @@ namespace hpx { namespace util { for (std::size_t i = 0; i < pool_size_; ++i) { - io_service_ptr io_service(new boost::asio::io_service); - work_ptr work(new boost::asio::io_service::work(*io_service)); - io_services_.push_back(io_service); - work_.push_back(work); + io_services_.emplace_back(new boost::asio::io_service); + work_.emplace_back(initialize_work(*io_services_[i])); } } for (std::size_t i = 0; i < pool_size_; ++i) { - boost::shared_ptr thread(new boost::thread( - boost::bind(&io_service_pool::thread_run, this, i))); - threads_.push_back(thread); + boost::thread thread(boost::bind( + &io_service_pool::thread_run, this, i)); + threads_.emplace_back(std::move(thread)); } next_io_service_ = 0; @@ -152,7 +146,7 @@ namespace hpx { namespace util { // Wait for all threads in the pool to exit. for (std::size_t i = 0; i < threads_.size(); ++i) - threads_[i]->join(); + threads_[i].join(); threads_.clear(); } @@ -166,8 +160,6 @@ namespace hpx { namespace util { if (!stopped_) { // Explicitly inform all work to exit. - for (std::size_t i = 0; i < work_.size(); ++i) - work_[i].reset(); work_.clear(); // Explicitly stop all io_services.