Timer

Collaboration diagram for Timer:

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 Documentation

timer callback parameter

Definition at line 69 of file timer.h.

typedef uint64 protlib::timer_id_t

timer ID

Each timer of a timer manager has a unique timer ID.

Definition at line 66 of file timer.h.


Function Documentation

static void protlib::add_timespecs ( struct timespec &  ts1,
struct timespec &  ts2,
struct timespec &  res 
) [inline, static]

uint32 protlib::TimerManager::check_timers (  )  [inherited]

check for elapsed timers

Check if timers have elapsed and call their callbacks.

Returns:
the number of elapsed timers.

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]

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]

static void protlib::fill_timespec ( struct timespec &  ts,
int32  sec,
int32  msec 
) [inline, static]

static void protlib::gettimeofday_timespec ( struct timespec &  ts  )  [inline, static]

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.

See also:
collect_elapsed()

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]

bool protlib::TimerManager::restart_relative ( timer_id_t  id,
int32  sec,
int32  msec = 0 
) [inherited]

timer_id_t protlib::TimerManager::start_absolute ( TimerCallback tc,
int32  sec,
int32  msec = 0,
timer_callback_param_t  tcp = NULL 
) [inherited]

timer_id_t protlib::TimerManager::start_relative ( TimerCallback tc,
int32  sec,
int32  msec = 0,
timer_callback_param_t  tcp = NULL 
) [inherited]

bool protlib::TimerManager::stop ( timer_id_t  id  )  [inherited]

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]

Initialize a timer. If get_id is set (default) the timer gets a unique ID, otherwise the ID of the timer is 0.

Definition at line 514 of file timer.cpp.

References protlib::TimerManager::TimerManager::timer::next_id.

protlib::TimerManager::TimerManager (  )  [inherited]

protlib::TimerManager::~TimerManager (  )  [inherited]


Variable Documentation

timer_id_t protlib::TimerManager::TimerManager::timer::next_id = 1 [static, inherited]

timer ID counter

This holds the timer ID of the next timer.

Definition at line 123 of file timer.h.

Referenced by protlib::TimerManager::TimerManager::timer::timer().


Generated on Fri Aug 14 23:38:37 2009 for Ariba by  doxygen 1.5.8