pion-net
4.0.9
|
#include <PionScheduler.hpp>
Inherits noncopyable.
Inherited by pion::PionMultiThreadScheduler.
Public Member Functions | |
PionScheduler (void) | |
constructs a new PionScheduler | |
virtual | ~PionScheduler () |
virtual destructor | |
virtual void | startup (void) |
Starts the thread scheduler (this is called automatically when necessary) | |
virtual void | shutdown (void) |
Stops the thread scheduler (this is called automatically when the program exits) | |
void | join (void) |
the calling thread will sleep until the scheduler has stopped | |
void | addActiveUser (void) |
void | removeActiveUser (void) |
unregisters an active user with the thread scheduler | |
bool | isRunning (void) const |
returns true if the scheduler is running | |
void | setNumThreads (const boost::uint32_t n) |
sets the number of threads to be used (these are shared by all servers) | |
boost::uint32_t | getNumThreads (void) const |
returns the number of threads currently in use | |
void | setLogger (PionLogger log_ptr) |
sets the logger to be used | |
PionLogger | getLogger (void) |
returns the logger currently in use | |
virtual boost::asio::io_service & | getIOService (void)=0 |
returns an async I/O service used to schedule work | |
virtual void | post (boost::function0< void > work_func) |
void | keepRunning (boost::asio::io_service &my_service, boost::asio::deadline_timer &my_timer) |
void | processServiceWork (boost::asio::io_service &service) |
processes work passed to the asio service & handles uncaught exceptions | |
Static Public Member Functions | |
static void | sleep (boost::uint32_t sleep_sec, boost::uint32_t sleep_nsec) |
template<typename ConditionType , typename LockType > | |
static void | sleep (ConditionType &wakeup_condition, LockType &wakeup_lock, boost::uint32_t sleep_sec, boost::uint32_t sleep_nsec) |
Protected Member Functions | |
virtual void | stopServices (void) |
stops all services used to schedule work | |
virtual void | stopThreads (void) |
stops all threads used to perform work | |
virtual void | finishServices (void) |
finishes all services used to schedule work | |
virtual void | finishThreads (void) |
finishes all threads used to perform work | |
Static Protected Member Functions | |
static boost::xtime | getWakeupTime (boost::uint32_t sleep_sec, boost::uint32_t sleep_nsec) |
Protected Attributes | |
boost::mutex | m_mutex |
mutex to make class thread-safe | |
PionLogger | m_logger |
primary logging interface used by this class | |
boost::condition | m_no_more_active_users |
condition triggered when there are no more active users | |
boost::condition | m_scheduler_has_stopped |
condition triggered when the scheduler has stopped | |
boost::uint32_t | m_num_threads |
total number of worker threads in the pool | |
boost::uint32_t | m_active_users |
the scheduler will not shutdown until there are no more active users | |
bool | m_is_running |
true if the thread scheduler is running | |
Static Protected Attributes | |
static const boost::uint32_t | DEFAULT_NUM_THREADS = 8 |
default number of worker threads in the thread pool | |
static const boost::uint32_t | NSEC_IN_SECOND = 1000000000 |
number of nanoseconds in one full second (10 ^ 9) | |
static const boost::uint32_t | MICROSEC_IN_SECOND = 1000000 |
number of microseconds in one full second (10 ^ 6) | |
static const boost::uint32_t | KEEP_RUNNING_TIMER_SECONDS = 5 |
number of seconds a timer should wait for to keep the IO services running |
PionScheduler: combines Boost.ASIO with a managed thread pool for scheduling
Definition at line 34 of file PionScheduler.hpp.
void pion::PionScheduler::addActiveUser | ( | void | ) |
registers an active user with the thread scheduler. Shutdown of the PionScheduler is deferred until there are no more active users. This ensures that any work queued will not reference destructed objects
Definition at line 87 of file PionScheduler.cpp.
References m_active_users, m_is_running, m_mutex, and startup().
Referenced by pion::net::TCPServer::start().
boost::xtime pion::PionScheduler::getWakeupTime | ( | boost::uint32_t | sleep_sec, |
boost::uint32_t | sleep_nsec | ||
) | [static, protected] |
calculates a wakeup time in boost::xtime format
sleep_sec | number of seconds to sleep for |
sleep_nsec | number of nanoseconds to sleep for |
Definition at line 101 of file PionScheduler.cpp.
References NSEC_IN_SECOND.
void pion::PionScheduler::keepRunning | ( | boost::asio::io_service & | my_service, |
boost::asio::deadline_timer & | my_timer | ||
) |
thread function used to keep the io_service running
my_service | IO service used to re-schedule keepRunning() |
my_timer | deadline timer used to keep the IO service active while running |
Definition at line 76 of file PionScheduler.cpp.
References KEEP_RUNNING_TIMER_SECONDS, and m_is_running.
Referenced by pion::PionSingleServiceScheduler::startup(), and pion::PionOneToOneScheduler::startup().
virtual void pion::PionScheduler::post | ( | boost::function0< void > | work_func | ) | [inline, virtual] |
schedules work to be performed by one of the pooled threads
work_func | work function to be executed |
Definition at line 88 of file PionScheduler.hpp.
static void pion::PionScheduler::sleep | ( | boost::uint32_t | sleep_sec, |
boost::uint32_t | sleep_nsec | ||
) | [inline, static] |
puts the current thread to sleep for a specific period of time
sleep_sec | number of entire seconds to sleep for |
sleep_nsec | number of nanoseconds to sleep for (10^-9 in 1 second) |
Definition at line 107 of file PionScheduler.hpp.
Referenced by pion::net::TCPServer::stop().
static void pion::PionScheduler::sleep | ( | ConditionType & | wakeup_condition, |
LockType & | wakeup_lock, | ||
boost::uint32_t | sleep_sec, | ||
boost::uint32_t | sleep_nsec | ||
) | [inline, static] |
puts the current thread to sleep for a specific period of time, or until a wakeup condition is signaled
wakeup_condition | if signaled, the condition will wakeup the thread early |
wakeup_lock | scoped lock protecting the wakeup condition |
sleep_sec | number of entire seconds to sleep for |
sleep_nsec | number of nanoseconds to sleep for (10^-9 in 1 second) |
Definition at line 122 of file PionScheduler.hpp.