![]() |
Classes | |
class | protlib::TimerCallback |
Timer Callback. More... | |
class | protlib::TimerManager |
Timer Manager. More... | |
Namespaces | |
namespace | protlib |
Files | |
file | timer.h |
Typedefs | |
typedef uint64 | protlib::timer_id_t |
timer ID | |
typedef void * | protlib::timer_callback_param_t |
timer callback parameter | |
Functions | |
static void | protlib::normalize_timespec (struct timespec &ts) |
static void | protlib::fill_timespec (struct timespec &ts, int32 sec, int32 msec) |
static void | protlib::add_timespecs (struct timespec &ts1, struct timespec &ts2, struct timespec &res) |
static void | protlib::gettimeofday_timespec (struct timespec &ts) |
protlib::TimerManager::TimerManager () | |
constructor | |
protlib::TimerManager::~TimerManager () | |
destructor | |
timer_id_t | protlib::TimerManager::start_relative (TimerCallback *tc, int32 sec, int32 msec=0, timer_callback_param_t tcp=NULL) |
start relative timer | |
timer_id_t | protlib::TimerManager::start_absolute (TimerCallback *tc, int32 sec, int32 msec=0, timer_callback_param_t tcp=NULL) |
start absolute timer | |
bool | protlib::TimerManager::restart_relative (timer_id_t id, int32 sec, int32 msec=0) |
restart relative timer | |
bool | protlib::TimerManager::restart_absolute (timer_id_t id, int32 sec, int32 msec=0) |
restart absolute timer | |
bool | protlib::TimerManager::stop (timer_id_t id) |
stop timer | |
uint32 | protlib::TimerManager::check_timers () |
check for elapsed timers | |
uint32 | protlib::TimerManager::check_timers_wait (int32 msec) |
check for elapsed timers or wait for next timer event. | |
uint32 | protlib::TimerManager::stop_all () |
stop all timers | |
uint32 | protlib::TimerManager::cleanup () |
cleanup hashmap and list | |
void | protlib::TimerManager::insert_into_list (timer *t) |
insert into list | |
void | protlib::TimerManager::delete_from_list (timer *t) |
delete timer from list | |
timer * | protlib::TimerManager::collect_elapsed () |
collect elapsed timers | |
uint32 | protlib::TimerManager::process_elapsed () |
process elapsed timers | |
protlib::TimerManager::timer::timer (struct timespec &ts, TimerCallback *tc, timer_callback_param_t tcp, bool get_id=true) | |
bool | protlib::TimerManager::timer::operator<= (const timer &t) |
void | protlib::TimerManager::timer::do_callback () |
execute callback | |
Variables | |
static timer_id_t | protlib::TimerManager::timer::next_id = 1 |
timer ID counter |
typedef void* protlib::timer_callback_param_t |
typedef uint64 protlib::timer_id_t |
static void protlib::add_timespecs | ( | struct timespec & | ts1, | |
struct timespec & | ts2, | |||
struct timespec & | res | |||
) | [inline, static] |
Definition at line 83 of file timer.cpp.
References protlib::normalize_timespec().
Referenced by protlib::TimerManager::check_timers_wait(), protlib::TimerManager::restart_relative(), and protlib::TimerManager::start_relative().
uint32 protlib::TimerManager::check_timers | ( | ) | [inherited] |
check for elapsed timers
Check if timers have elapsed and call their callbacks.
Definition at line 287 of file timer.cpp.
References protlib::TimerManager::collect_elapsed(), protlib::TimerManager::mutex, and protlib::TimerManager::process_elapsed().
uint32 protlib::TimerManager::check_timers_wait | ( | int32 | msec | ) | [inherited] |
check for elapsed timers or wait for next timer event.
Like check_timers() but waits msec milliseconds for a timer to elapse.
Definition at line 298 of file timer.cpp.
References protlib::add_timespecs(), protlib::TimerManager::collect_elapsed(), protlib::TimerManager::cond, protlib::log::DEBUG_LOG, protlib::fill_timespec(), protlib::TimerManager::first(), protlib::gettimeofday_timespec(), protlib::TimerManager::TimerManager::timer::id, Log, protlib::log::LOG_NORMAL, protlib::TimerManager::mutex, protlib::TimerManager::process_elapsed(), and protlib::TimerManager::TimerManager::timer::time.
Referenced by protlib::TimerModule::process_elapsed_timers().
uint32 protlib::TimerManager::cleanup | ( | ) | [private, inherited] |
cleanup hashmap and list
Stop all timers without locking the mutex. So this can be called safely inside the TimerManager constructor.
Definition at line 356 of file timer.cpp.
References protlib::TimerManager::active_timerlist, and protlib::TimerManager::hashmap.
Referenced by protlib::TimerManager::stop_all(), and protlib::TimerManager::~TimerManager().
TimerManager::timer * protlib::TimerManager::collect_elapsed | ( | ) | [private, inherited] |
collect elapsed timers
Collect all elapsed timers in the elapsed_timerlist and delete them already from the hashmap. The timers are deleted in process_elapsed(). You must lock the TimerManager mutex before collecting timers. When timers have elapsed, the condition is signaled.
Definition at line 443 of file timer.cpp.
References protlib::TimerManager::active_timerlist, protlib::TimerManager::cond, protlib::log::DEBUG_LOG, protlib::TimerManager::elapsed_timerlist, protlib::TimerManager::first(), protlib::gettimeofday_timespec(), protlib::TimerManager::hashmap, protlib::TimerManager::TimerManager::timer::id, Log, and protlib::log::LOG_NORMAL.
Referenced by protlib::TimerManager::check_timers(), and protlib::TimerManager::check_timers_wait().
void protlib::TimerManager::delete_from_list | ( | timer * | t | ) | [private, inherited] |
delete timer from list
Delete a timer from the ordered timer list. The timer object is NOT freed because it may be needed for executing its callback or for restarting. The timer objects must be linked correctly, no checking is done.
Definition at line 421 of file timer.cpp.
References protlib::TimerManager::active_timerlist, protlib::log::DEBUG_LOG, protlib::TimerManager::first(), protlib::TimerManager::TimerManager::timer::id, Log, and protlib::log::LOG_NORMAL.
Referenced by protlib::TimerManager::restart_absolute(), protlib::TimerManager::restart_relative(), and protlib::TimerManager::stop().
void protlib::TimerManager::TimerManager::timer::do_callback | ( | ) | [inline, inherited] |
execute callback
Definition at line 544 of file timer.cpp.
References protlib::TimerManager::TimerManager::timer::callback, protlib::TimerManager::TimerManager::timer::param, and protlib::TimerCallback::timer_expired().
Referenced by protlib::TimerManager::process_elapsed().
static void protlib::fill_timespec | ( | struct timespec & | ts, | |
int32 | sec, | |||
int32 | msec | |||
) | [inline, static] |
fills in timespec with sec+msec, msec may be larger than 999!
Definition at line 72 of file timer.cpp.
References protlib::normalize_timespec().
Referenced by protlib::TimerManager::check_timers_wait(), protlib::TimerManager::restart_absolute(), protlib::TimerManager::restart_relative(), protlib::TimerManager::start_absolute(), and protlib::TimerManager::start_relative().
static void protlib::gettimeofday_timespec | ( | struct timespec & | ts | ) | [inline, static] |
Definition at line 89 of file timer.cpp.
Referenced by protlib::TimerManager::check_timers_wait(), protlib::TimerManager::collect_elapsed(), protlib::TimerManager::restart_relative(), and protlib::TimerManager::start_relative().
void protlib::TimerManager::insert_into_list | ( | timer * | t | ) | [inline, private, inherited] |
insert into list
Insert a timer object into the timer list. Timers are stored in an ordered list, so when checking for elapsed timers it's enough to check timers beginning at the front end until one is still running.
Definition at line 383 of file timer.cpp.
References protlib::TimerManager::active_timerlist, protlib::log::DEBUG_LOG, protlib::TimerManager::TimerManager::timer::id, Log, and protlib::log::LOG_NORMAL.
Referenced by protlib::TimerManager::restart_absolute(), protlib::TimerManager::restart_relative(), protlib::TimerManager::start_absolute(), and protlib::TimerManager::start_relative().
static void protlib::normalize_timespec | ( | struct timespec & | ts | ) | [inline, static] |
Definition at line 57 of file timer.cpp.
Referenced by protlib::add_timespecs(), and protlib::fill_timespec().
bool protlib::TimerManager::TimerManager::timer::operator<= | ( | const timer & | t | ) | [inline, inherited] |
Check which timer goes off eralier. The timespec structores of the timers are expected to have correct format.
Definition at line 532 of file timer.cpp.
References protlib::TimerManager::TimerManager::timer::time.
uint32 protlib::TimerManager::process_elapsed | ( | ) | [private, inherited] |
process elapsed timers
Process a list of timers by executing the callback routines and deleting the timer objects. They are NOT deleted from the TimerManager hashmap. The mutex should not be locked when callbacks are executed, because it is unpossible to start a new timer inside a callback routine when the mutex is still locked.
Definition at line 487 of file timer.cpp.
References protlib::TimerManager::TimerManager::timer::do_callback(), and protlib::TimerManager::elapsed_timerlist.
Referenced by protlib::TimerManager::check_timers(), and protlib::TimerManager::check_timers_wait().
bool protlib::TimerManager::restart_absolute | ( | timer_id_t | id, | |
int32 | sec, | |||
int32 | msec = 0 | |||
) | [inherited] |
restart absolute timer
Restart a timer and set the alarm to an absolute time. The timer must exist and go off in the future.
Definition at line 231 of file timer.cpp.
References protlib::TimerManager::cond, protlib::log::DEBUG_LOG, protlib::TimerManager::delete_from_list(), protlib::fill_timespec(), protlib::TimerManager::hashmap, protlib::TimerManager::insert_into_list(), Log, protlib::log::LOG_NORMAL, protlib::TimerManager::mutex, and protlib::TimerManager::TimerManager::timer::time.
Referenced by protlib::TimerModule::restart_timer().
bool protlib::TimerManager::restart_relative | ( | timer_id_t | id, | |
int32 | sec, | |||
int32 | msec = 0 | |||
) | [inherited] |
restart relative timer
Restart a timer and set the alarm relative to the current time. The timer must exist and go off in the future.
Definition at line 194 of file timer.cpp.
References protlib::add_timespecs(), protlib::TimerManager::cond, protlib::log::DEBUG_LOG, protlib::TimerManager::delete_from_list(), protlib::fill_timespec(), protlib::gettimeofday_timespec(), protlib::TimerManager::hashmap, protlib::TimerManager::insert_into_list(), Log, protlib::log::LOG_NORMAL, protlib::TimerManager::mutex, and protlib::TimerManager::TimerManager::timer::time.
Referenced by protlib::TimerModule::restart_timer().
timer_id_t protlib::TimerManager::start_absolute | ( | TimerCallback * | tc, | |
int32 | sec, | |||
int32 | msec = 0 , |
|||
timer_callback_param_t | tcp = NULL | |||
) | [inherited] |
start absolute timer
Start an absolute timer.
Definition at line 164 of file timer.cpp.
References protlib::TimerManager::cond, protlib::log::ERROR_LOG, protlib::fill_timespec(), protlib::TimerManager::hashmap, protlib::TimerManager::TimerManager::timer::id, protlib::TimerManager::insert_into_list(), Log, protlib::log::LOG_CRIT, and protlib::TimerManager::mutex.
Referenced by protlib::TimerModule::start_timer().
timer_id_t protlib::TimerManager::start_relative | ( | TimerCallback * | tc, | |
int32 | sec, | |||
int32 | msec = 0 , |
|||
timer_callback_param_t | tcp = NULL | |||
) | [inherited] |
start relative timer
Start a timer relative to current time.
Definition at line 129 of file timer.cpp.
References protlib::add_timespecs(), protlib::TimerManager::cond, protlib::log::ERROR_LOG, protlib::fill_timespec(), protlib::gettimeofday_timespec(), protlib::TimerManager::hashmap, protlib::TimerManager::TimerManager::timer::id, protlib::TimerManager::insert_into_list(), Log, protlib::log::LOG_CRIT, and protlib::TimerManager::mutex.
Referenced by protlib::TimerModule::start_timer().
bool protlib::TimerManager::stop | ( | timer_id_t | id | ) | [inherited] |
stop timer
Stop the given timer.
Definition at line 258 of file timer.cpp.
References protlib::TimerManager::cond, protlib::log::DEBUG_LOG, protlib::TimerManager::delete_from_list(), protlib::TimerManager::hashmap, Log, protlib::log::LOG_NORMAL, and protlib::TimerManager::mutex.
Referenced by protlib::TimerModule::stop_timer().
uint32 protlib::TimerManager::stop_all | ( | ) | [inherited] |
stop all timers
Stop all timers.
Definition at line 339 of file timer.cpp.
References protlib::TimerManager::cleanup(), protlib::TimerManager::cond, and protlib::TimerManager::mutex.
Referenced by protlib::TimerModule::stop_all_timers().
protlib::TimerManager::TimerManager::timer::timer | ( | struct timespec & | ts, | |
TimerCallback * | tc, | |||
timer_callback_param_t | tcp, | |||
bool | get_id = true | |||
) | [inherited] |
protlib::TimerManager::TimerManager | ( | ) | [inherited] |
constructor
Initialize a TimerManager object.
Definition at line 97 of file timer.cpp.
References protlib::TimerManager::cond, protlib::log::DEBUG_LOG, Log, protlib::log::LOG_NORMAL, protlib::TimerManager::mutex, protlib::TimerManager::mutex_attr, PTHREAD_MUTEX_ERRORCHECK, PTHREAD_MUTEX_NORMAL, and pthread_mutexattr_settype.
protlib::TimerManager::~TimerManager | ( | ) | [inherited] |
destructor
Destroy TimerManager.
Definition at line 113 of file timer.cpp.
References protlib::TimerManager::cleanup(), protlib::TimerManager::cond, DLog, protlib::TimerManager::mutex, and protlib::TimerManager::mutex_attr.
timer_id_t protlib::TimerManager::TimerManager::timer::next_id = 1 [static, inherited] |