pion::scheduler Class Reference

#include <scheduler.hpp>

Inherited by pion::multi_thread_scheduler.

List of all members.

Public Member Functions

 scheduler (void)
 constructs a new scheduler
virtual ~scheduler ()
 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 add_active_user (void)
void remove_active_user (void)
 unregisters an active user with the thread scheduler
bool is_running (void) const
 returns true if the scheduler is running
void set_num_threads (const boost::uint32_t n)
 sets the number of threads to be used (these are shared by all servers)
boost::uint32_t get_num_threads (void) const
 returns the number of threads currently in use
void set_logger (logger log_ptr)
 sets the logger to be used
logger get_logger (void)
 returns the logger currently in use
virtual boost::asio::io_service & get_io_service (void)=0
 returns an async I/O service used to schedule work
virtual void post (boost::function0< void > work_func)
void keep_running (boost::asio::io_service &my_service, boost::asio::deadline_timer &my_timer)
void process_service_work (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 stop_services (void)
 stops all services used to schedule work
virtual void stop_threads (void)
 stops all threads used to perform work
virtual void finish_services (void)
 finishes all services used to schedule work
virtual void finish_threads (void)
 finishes all threads used to perform work

Static Protected Member Functions

static boost::system_time get_wakeup_time (boost::uint32_t sleep_sec, boost::uint32_t sleep_nsec)

Protected Attributes

boost::mutex m_mutex
 mutex to make class thread-safe
logger 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

Detailed Description

scheduler: combines Boost.ASIO with a managed thread pool for scheduling

Definition at line 34 of file scheduler.hpp.


Member Function Documentation

void pion::scheduler::add_active_user ( void   ) 

registers an active user with the thread scheduler. Shutdown of the scheduler is deferred until there are no more active users. This ensures that any work queued will not reference destructed objects

Definition at line 88 of file scheduler.cpp.

References m_active_users, m_is_running, m_mutex, and startup().

Referenced by pion::tcp::server::start().

boost::system_time pion::scheduler::get_wakeup_time ( boost::uint32_t  sleep_sec,
boost::uint32_t  sleep_nsec 
) [static, protected]

calculates a wakeup time in boost::system_time format

Parameters:
sleep_sec number of seconds to sleep for
sleep_nsec number of nanoseconds to sleep for
Returns:
boost::system_time time to wake up from sleep

Definition at line 102 of file scheduler.cpp.

void pion::scheduler::keep_running ( boost::asio::io_service &  my_service,
boost::asio::deadline_timer &  my_timer 
)

thread function used to keep the io_service running

Parameters:
my_service IO service used to re-schedule keep_running()
my_timer deadline timer used to keep the IO service active while running

Definition at line 77 of file scheduler.cpp.

References KEEP_RUNNING_TIMER_SECONDS, and m_is_running.

Referenced by pion::one_to_one_scheduler::startup(), and pion::single_service_scheduler::startup().

virtual void pion::scheduler::post ( boost::function0< void >  work_func  )  [inline, virtual]

schedules work to be performed by one of the pooled threads

Parameters:
work_func work function to be executed

Definition at line 88 of file scheduler.hpp.

template<typename ConditionType , typename LockType >
static void pion::scheduler::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

Parameters:
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 scheduler.hpp.

static void pion::scheduler::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

Parameters:
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 scheduler.hpp.

Referenced by pion::tcp::server::stop().


The documentation for this class was generated from the following files:

Generated on 16 Sep 2013 for pion by  doxygen 1.6.1