Ejemplo n.º 1
0
    io_service_pool::io_service_pool(std::size_t pool_size,
            char const* pool_name, char const* name_postfix)
      : next_io_service_(0), stopped_(false),
        pool_size_(pool_size),
        on_start_thread_(),
        on_stop_thread_(),
        pool_name_(pool_name), pool_name_postfix_(name_postfix),
        waiting_(false), wait_barrier_(pool_size + 1),
        continue_barrier_(pool_size + 1)
    {
        LPROGRESS_ << pool_name;

        if (pool_size == 0)
        {
            HPX_THROW_EXCEPTION(bad_parameter,
                "io_service_pool::io_service_pool",
                "io_service_pool size is 0");
            return;
        }

        // Give all the io_services work to do so that their run() functions
        // will not exit until they are explicitly stopped.
        for (std::size_t i = 0; i < pool_size; ++i)
        {
            io_services_.emplace_back(new boost::asio::io_service);
            work_.emplace_back(initialize_work(*io_services_[i]));
        }
    }
Ejemplo n.º 2
0
    bool io_service_pool::run_locked(std::size_t num_threads, bool join_threads,
        compat::barrier* startup)
    {
        if (io_services_.empty())
        {
            pool_size_ = num_threads;

            for (std::size_t i = 0; i < num_threads; ++i)
            {
                io_services_.emplace_back(new boost::asio::io_service);
                work_.emplace_back(initialize_work(*io_services_[i]));
            }
        }

        for (std::size_t i = 0; i < num_threads; ++i)
        {
            compat::thread t(
                &io_service_pool::thread_run, this, i, startup);
            threads_.emplace_back(std::move(t));
        }

        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;
    }
Ejemplo n.º 3
0
    void io_service_pool::wait_locked()
    {
        if (!stopped_) {
            // Clear work so that the run functions return when all work is done
            waiting_ = true;
            work_.clear();
            wait_barrier_.wait();

            // Add back the work guard and restart the services
            waiting_ = false;
            for (std::size_t i = 0; i < pool_size_; ++i)
            {
                work_.emplace_back(initialize_work(*io_services_[i]));
                io_services_[i]->reset();
            }

            continue_barrier_.wait();
        }
    }
void PSYoungGen::initialize(ReservedSpace rs, size_t alignment) {
  initialize_virtual_space(rs, alignment);
  initialize_work();
}
Ejemplo n.º 5
0
 // Redundant initializations okay.
 void initialize() {
   // Double-check dirty read idiom.
   if (!_initialized) initialize_work();
 }