thread_state_enum at_timer(SchedulingPolicy& scheduler, boost::chrono::steady_clock::time_point& abs_time, thread_id_type const& thrd, thread_state_enum newstate, thread_state_ex_enum newstate_ex, thread_priority priority) { if (HPX_UNLIKELY(!thrd)) { HPX_THROW_EXCEPTION(null_thread_id, "threads::detail::at_timer", "NULL thread id encountered"); return terminated; } // create a new thread in suspended state, which will execute the // requested set_state when timer fires and will re-awaken this thread, // allowing the deadline_timer to go out of scope gracefully thread_id_type self_id = get_self_id(); boost::shared_ptr<boost::atomic<bool> > triggered( boost::make_shared<boost::atomic<bool> >(false)); thread_init_data data( boost::bind(&wake_timer_thread, thrd, newstate, newstate_ex, priority, self_id, triggered), "wake_timer", 0, priority); thread_id_type wake_id = invalid_thread_id; create_thread(&scheduler, data, wake_id, suspended); // create timer firing in correspondence with given time typedef boost::asio::basic_deadline_timer< boost::chrono::steady_clock , util::chrono_traits<boost::chrono::steady_clock> > deadline_timer; deadline_timer t ( get_thread_pool("timer-pool")->get_io_service(), abs_time); // let the timer invoke the set_state on the new (suspended) thread t.async_wait(boost::bind(&detail::set_thread_state, wake_id, pending, wait_timeout, priority, std::size_t(-1), boost::ref(throws))); // this waits for the thread to be reactivated when the timer fired // if it returns signaled the timer has been canceled, otherwise // the timer fired and the wake_timer_thread above has been executed bool oldvalue = false; thread_state_ex_enum statex = get_self().yield(suspended); if (wait_timeout != statex && triggered->compare_exchange_strong(oldvalue, true)) //-V601 { // wake_timer_thread has not been executed yet, cancel timer t.cancel(); } return terminated; }
service_executor::service_executor( char const* pool_name, char const* pool_name_suffix) : pool_(get_thread_pool(pool_name, pool_name_suffix)), task_count_(0), shutdown_sem_(0) { if (!pool_) { HPX_THROW_EXCEPTION(bad_parameter, "service_executor::service_executor", "couldn't retrieve thread pool: " + std::string(pool_name)); } }
int get_nb_threads(){ pool = get_thread_pool(); return pool -> nb_threads; }
threads::detail::thread_pool_base& get_thread_pool(std::size_t pool_index) { return get_thread_pool(get_pool_name(pool_index)); }