10 #include <boost/exception/diagnostic_information.hpp> 11 #include <boost/date_time/posix_time/posix_time_duration.hpp> 12 #include <pion/scheduler.hpp> 30 boost::mutex::scoped_lock scheduler_lock(
m_mutex);
34 PION_LOG_INFO(
m_logger,
"Shutting down the thread scheduler");
49 PION_LOG_INFO(
m_logger,
"The thread scheduler has shutdown");
70 boost::mutex::scoped_lock scheduler_lock(
m_mutex);
78 boost::asio::deadline_timer& my_timer)
84 boost::ref(my_service), boost::ref(my_timer)));
91 boost::mutex::scoped_lock scheduler_lock(
m_mutex);
97 boost::mutex::scoped_lock scheduler_lock(
m_mutex);
103 boost::uint32_t sleep_nsec)
105 return boost::get_system_time() + boost::posix_time::seconds(sleep_sec) + boost::posix_time::microseconds(sleep_nsec / 1000);
112 }
catch (std::exception& e) {
113 PION_LOG_ERROR(
m_logger, boost::diagnostic_information(e));
115 PION_LOG_ERROR(
m_logger,
"caught unrecognized exception");
126 boost::mutex::scoped_lock scheduler_lock(
m_mutex);
129 PION_LOG_INFO(
m_logger,
"Starting thread scheduler");
139 this, boost::ref(m_service)) ));
140 m_thread_pool.push_back(new_thread);
151 boost::mutex::scoped_lock scheduler_lock(
m_mutex);
154 PION_LOG_INFO(
m_logger,
"Starting thread scheduler");
160 m_service_pool.push_back(service_ptr);
164 for (service_pool_type::iterator i = m_service_pool.begin(); i != m_service_pool.end(); ++i) {
171 this, boost::ref(m_service_pool[n]->first)) ));
172 m_thread_pool.push_back(new_thread);
boost::condition m_scheduler_has_stopped
condition triggered when the scheduler has stopped
virtual void stop_threads(void)
stops all threads used to perform work
virtual void stop_services(void)
stops all services used to schedule work
bool m_is_running
true if the thread scheduler is running
static const boost::uint32_t DEFAULT_NUM_THREADS
default number of worker threads in the thread pool
virtual void startup(void)
Starts the thread scheduler (this is called automatically when necessary)
virtual void finish_services(void)
finishes all services used to schedule work
boost::condition m_no_more_active_users
condition triggered when there are no more active users
static boost::system_time get_wakeup_time(boost::uint32_t sleep_sec, boost::uint32_t sleep_nsec)
static const boost::uint32_t MICROSEC_IN_SECOND
number of microseconds in one full second (10 ^ 6)
void remove_active_user(void)
unregisters an active user with the thread scheduler
boost::uint32_t m_num_threads
total number of worker threads in the pool
boost::mutex m_mutex
mutex to make class thread-safe
static const boost::uint32_t NSEC_IN_SECOND
number of nanoseconds in one full second (10 ^ 9)
logger m_logger
primary logging interface used by this class
virtual void shutdown(void)
Stops the thread scheduler (this is called automatically when the program exits)
boost::uint32_t m_active_users
the scheduler will not shutdown until there are no more active users
static const boost::uint32_t KEEP_RUNNING_TIMER_SECONDS
number of seconds a timer should wait for to keep the IO services running
typedef for a pair object where first is an IO service and second is a deadline timer ...
void keep_running(boost::asio::io_service &my_service, boost::asio::deadline_timer &my_timer)
virtual void startup(void)
Starts the thread scheduler (this is called automatically when necessary)
void add_active_user(void)
virtual void startup(void)
Starts the thread scheduler (this is called automatically when necessary)
void join(void)
the calling thread will sleep until the scheduler has stopped
void process_service_work(boost::asio::io_service &service)
processes work passed to the asio service & handles uncaught exceptions
virtual void finish_threads(void)
finishes all threads used to perform work