include/mb_timer.h File Reference

#include <sys/time.h>
#include <stdint.h>

Go to the source code of this file.

Defines

#define MB_TIMEVAL_SET(_tv, _sec, _usec)
#define MB_TIMEVAL_CP(_tv1, _tv2)
#define MB_TIMEVAL_SEC(_tv)   ((_tv)->tv_sec)
#define MB_TIMEVAL_USEC(_tv)   ((_tv)->tv_usec)
#define MB_TIMEVAL_LATER(a, b)
#define MB_TIMEVAL_LATER_INC(a, b)
#define MB_TIMEVAL_EQ(a, b)
#define MB_TIMEVAL_DIFF(a, b)
#define MB_TIMEVAL_ADD(a, b)
#define MB_TIMEVAL_DIV(a, b)

Typedefs

typedef uint32_t mbsec_t
typedef uint32_t mbusec_t
typedef struct _mb_timer mb_timer_t
typedef struct _mb_tman mb_tman_t
typedef struct timeval mb_timeval_t
typedef void(* mb_tmo_hdlr )(const mb_timeval_t *tmo, const mb_timeval_t *now, void *arg)

Functions

mb_tman_tmb_tman_new (void)
void mb_tman_free (mb_tman_t *tman)
mb_timer_tmb_tman_timeout (mb_tman_t *tman, const mb_timeval_t *tmo, mb_tmo_hdlr hdlr, void *arg)
int mb_tman_remove (mb_tman_t *tman, mb_timer_t *timer)
int mb_tman_next_timeout (mb_tman_t *tman, const mb_timeval_t *now, mb_timeval_t *tmo_after)
 Get how long to next timeout from this monent.
int mb_tman_handle_timeout (mb_tman_t *tman, mb_timeval_t *now)
void get_now (mb_timeval_t *tmo)


Define Documentation

#define MB_TIMEVAL_ADD ( a,
 ) 

Value:

do {                                    \
        (a)->tv_sec += (b)->tv_sec;             \
        (a)->tv_usec += (b)->tv_usec;           \
        if((a)->tv_usec >= 1000000) {           \
            (a)->tv_sec++;                      \
            (a)->tv_usec -= 1000000;            \
        }                                       \
    } while(0)

Definition at line 61 of file mb_timer.h.

#define MB_TIMEVAL_CP ( _tv1,
_tv2   ) 

Value:

do {                                    \
        (_tv1)->tv_sec = (_tv2)->tv_sec;        \
        (_tv1)->tv_usec = (_tv2)->tv_usec;      \
    } while(0)

Definition at line 34 of file mb_timer.h.

#define MB_TIMEVAL_DIFF ( a,
 ) 

Value:

do {                                    \
        (a)->tv_sec -= (b)->tv_sec;             \
        if((a)->tv_usec < (b)->tv_usec) {       \
            (a)->tv_sec--;                      \
            (a)->tv_usec += 1000000;            \
        }                                       \
        (a)->tv_usec -= (b)->tv_usec;           \
    } while(0)

Definition at line 52 of file mb_timer.h.

#define MB_TIMEVAL_DIV ( a,
 ) 

Value:

(((a)->tv_sec * 1000000.0 + (a)->tv_usec) /     \
     ((b)->tv_sec * 1000000.0 + (b)->tv_usec))

Definition at line 70 of file mb_timer.h.

#define MB_TIMEVAL_EQ ( a,
 ) 

Value:

((a)->tv_sec == (b)->tv_sec &&          \
     (a)->tv_usec == (b)->tv_usec)

Definition at line 49 of file mb_timer.h.

#define MB_TIMEVAL_LATER ( a,
 ) 

Value:

((a)->tv_sec > (b)->tv_sec ||           \
     ((a)->tv_sec == (b)->tv_sec &&             \
      (a)->tv_usec > (b)->tv_usec))

Definition at line 41 of file mb_timer.h.

#define MB_TIMEVAL_LATER_INC ( a,
 ) 

Value:

((a)->tv_sec > (b)->tv_sec ||           \
     ((a)->tv_sec == (b)->tv_sec &&             \
      (a)->tv_usec >= (b)->tv_usec))

Definition at line 45 of file mb_timer.h.

#define MB_TIMEVAL_SEC ( _tv   )     ((_tv)->tv_sec)

Definition at line 39 of file mb_timer.h.

#define MB_TIMEVAL_SET ( _tv,
_sec,
_usec   ) 

Value:

do {                                    \
        (_tv)->tv_sec = _sec;                   \
        (_tv)->tv_usec = _usec;                 \
    } while(0)

Definition at line 29 of file mb_timer.h.

#define MB_TIMEVAL_USEC ( _tv   )     ((_tv)->tv_usec)

Definition at line 40 of file mb_timer.h.


Typedef Documentation

typedef struct _mb_timer mb_timer_t

Definition at line 9 of file mb_timer.h.

typedef struct timeval mb_timeval_t

Definition at line 11 of file mb_timer.h.

typedef struct _mb_tman mb_tman_t

Definition at line 10 of file mb_timer.h.

typedef void(* mb_tmo_hdlr)(const mb_timeval_t *tmo, const mb_timeval_t *now, void *arg)

Definition at line 14 of file mb_timer.h.

typedef uint32_t mbsec_t

Definition at line 7 of file mb_timer.h.

typedef uint32_t mbusec_t

Definition at line 8 of file mb_timer.h.


Function Documentation

void get_now ( mb_timeval_t tmo  ) 

Definition at line 57 of file timertool.c.

void mb_tman_free ( mb_tman_t tman  ) 

Definition at line 42 of file timer.c.

int mb_tman_handle_timeout ( mb_tman_t tman,
mb_timeval_t now 
)

Definition at line 110 of file timer.c.

mb_tman_t* mb_tman_new ( void   ) 

Definition at line 24 of file timer.c.

int mb_tman_next_timeout ( mb_tman_t tman,
const mb_timeval_t now,
mb_timeval_t tmo_after 
)

Get how long to next timeout from this monent.

Returns:
0 for having next timeout, -1 for not more timeout.

Definition at line 91 of file timer.c.

int mb_tman_remove ( mb_tman_t tman,
mb_timer_t timer 
)

Definition at line 80 of file timer.c.

mb_timer_t* mb_tman_timeout ( mb_tman_t tman,
const mb_timeval_t tmo,
mb_tmo_hdlr  hdlr,
void *  arg 
)

Definition at line 47 of file timer.c.

SourceForge.net Logo