view src/mb_timer.h @ 151:d11aa8fc06c7

Fix bug of tanks do not show at right places. Since we avoid to dirty a subtree if root of a subtree have been dirty or hidden, it make children that was added into coord tree after a coord be dirty do not be marked with COF_DIRTY flag. To fix it, when a new coord is created, the parent is checked and mark new coord with COF_DIRTY flag if the parent is dirty. It forces new coords to be cleaned and transformed to right places.
author Thinker K.F. Li <thinker@branda.to>
date Fri, 26 Sep 2008 17:42:16 +0800
parents a6763f080da5
children 6749f6639924
line wrap: on
line source

#ifndef __MB_TIMER_H_
#define __MB_TIMER_H_

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

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);

extern mb_tman_t *mb_tman_new(void);
extern void mb_tman_free(mb_tman_t *tman);
extern mb_timer_t *mb_tman_timeout(mb_tman_t *tman,
				   const mb_timeval_t *tmo,
				   mb_tmo_hdlr hdlr, void *arg);
extern int mb_tman_remove(mb_tman_t *tman, mb_timer_t *timer);
extern int mb_tman_next_timeout(mb_tman_t *tman,
				const mb_timeval_t *now,
				mb_timeval_t *tmo_after);
extern int mb_tman_handle_timeout(mb_tman_t *tman, mb_timeval_t *now);

#define MB_TIMEVAL_SET(_tv, _sec, _usec)	\
    do {					\
	(_tv)->tv_sec = _sec;			\
	(_tv)->tv_usec = _usec;			\
    } while(0)
#define MB_TIMEVAL_CP(_tv1, _tv2)		\
    do {					\
	(_tv1)->tv_sec = (_tv2)->tv_sec;	\
	(_tv1)->tv_usec = (_tv2)->tv_usec;	\
    } while(0)
#define MB_TIMEVAL_SEC(_tv) ((_tv)->tv_sec)
#define MB_TIMEVAL_USEC(_tv) ((_tv)->tv_usec)
#define MB_TIMEVAL_LATER(a, b)			\
    ((a)->tv_sec > (b)->tv_sec ||		\
     ((a)->tv_sec == (b)->tv_sec &&		\
      (a)->tv_usec > (b)->tv_usec))
#define MB_TIMEVAL_LATER_INC(a, b)		\
    ((a)->tv_sec > (b)->tv_sec ||		\
     ((a)->tv_sec == (b)->tv_sec &&		\
      (a)->tv_usec >= (b)->tv_usec))
#define MB_TIMEVAL_EQ(a, b)			\
    ((a)->tv_sec == (b)->tv_sec &&		\
     (a)->tv_usec == (b)->tv_usec)
#define MB_TIMEVAL_DIFF(a, b)			\
    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)
#define MB_TIMEVAL_ADD(a, b)			\
    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)


extern void get_now(mb_timeval_t *tmo);


#endif /* __MB_TIMER_H_ */