예제 #1
0
 io_service_pool::~io_service_pool()
 {
     boost::mutex::scoped_lock l(mtx_);
     stop_locked();
     join_locked();
     clear_locked();
 }
예제 #2
0
 io_service_pool::~io_service_pool()
 {
     boost::lock_guard<boost::mutex> l(mtx_);
     stop_locked();
     join_locked();
     clear_locked();
 }
예제 #3
0
    bool io_service_pool::run(std::size_t num_threads, bool join_threads,
        compat::barrier* startup)
    {
        std::lock_guard<compat::mutex> l(mtx_);

        // Create a pool of threads to run all of the io_services.
        if (!threads_.empty())   // should be called only once
        {
            HPX_ASSERT(pool_size_ == io_services_.size());
            HPX_ASSERT(threads_.size() == io_services_.size());
            HPX_ASSERT(work_.size() == io_services_.size());

            if (join_threads)
                join_locked();

            return false;
        }

        // Give all the io_services work to do so that their run() functions
        // will not exit until they are explicitly stopped.
        if (!io_services_.empty())
            clear_locked();

        return run_locked(num_threads, join_threads, startup);
    }
예제 #4
0
 io_service_pool::~io_service_pool()
 {
     std::lock_guard<compat::mutex> l(mtx_);
     stop_locked();
     join_locked();
     clear_locked();
 }
예제 #5
0
    bool io_service_pool::run(bool join_threads)
    {
        boost::lock_guard<boost::mutex> l(mtx_);

        // Create a pool of threads to run all of the io_services.
        if (!threads_.empty())   // should be called only once
        {
            HPX_ASSERT(pool_size_ == io_services_.size());
            HPX_ASSERT(threads_.size() == io_services_.size());
            HPX_ASSERT(work_.size() == io_services_.size());

            if (join_threads)
                join_locked();

            return false;
        }

        // Give all the io_services work to do so that their run() functions
        // will not exit until they are explicitly stopped.
        if (!io_services_.empty())
            clear_locked();

        if (io_services_.empty())
        {
            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);
            }
        }

        for (std::size_t i = 0; i < pool_size_; ++i)
        {
            boost::shared_ptr<boost::thread> thread(new boost::thread(
                boost::bind(&io_service_pool::thread_run, this, i)));
            threads_.push_back(thread);
        }

        next_io_service_ = 0;
        stopped_ = false;

        HPX_ASSERT(pool_size_ == io_services_.size());
        HPX_ASSERT(threads_.size() == io_services_.size());
        HPX_ASSERT(work_.size() == io_services_.size());

        if (join_threads)
            join_locked();

        return true;
    }
예제 #6
0
 void io_service_pool::clear()
 {
     boost::lock_guard<boost::mutex> l(mtx_);
     clear_locked();
 }
예제 #7
0
 void io_service_pool::clear()
 {
     boost::mutex::scoped_lock l(mtx_);
     clear_locked();
 }
예제 #8
0
 void io_service_pool::clear()
 {
     std::lock_guard<compat::mutex> l(mtx_);
     clear_locked();
 }