annotate src/mb_timer.h @ 60:0211417ee532

* linux types declaration
author "Mat <MatLinuxer2@gmail.com>"
date Mon, 11 Aug 2008 14:46:10 +0800
parents 46b77c92d118
children db5f203d7c19
rev   line source
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #ifndef __MB_TIMER_H_
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #define __MB_TIMER_H_
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
4 #include <sys/time.h>
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
5
60
0211417ee532 * linux types declaration
"Mat <MatLinuxer2@gmail.com>"
parents: 46
diff changeset
6 #ifdef __linux__
0211417ee532 * linux types declaration
"Mat <MatLinuxer2@gmail.com>"
parents: 46
diff changeset
7 #include <linux/types.h>
0211417ee532 * linux types declaration
"Mat <MatLinuxer2@gmail.com>"
parents: 46
diff changeset
8 #endif
0211417ee532 * linux types declaration
"Mat <MatLinuxer2@gmail.com>"
parents: 46
diff changeset
9
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 typedef uint32_t mbsec_t;
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 typedef uint32_t mbusec_t;
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 typedef struct _mb_timer mb_timer_t;
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 typedef struct _mb_tman mb_tman_t;
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
14 typedef struct timeval mb_timeval_t;
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
16
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
17 typedef void (*mb_tmo_hdlr)(const mb_timeval_t *tmo,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
18 const mb_timeval_t *now,
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 void *arg);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 extern mb_tman_t *mb_tman_new(void);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 extern void mb_tman_free(mb_tman_t *tman);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 extern mb_timer_t *mb_tman_timeout(mb_tman_t *tman,
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
24 const mb_timeval_t *tmo,
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 mb_tmo_hdlr hdlr, void *arg);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 extern int mb_tman_remove(mb_tman_t *tman, mb_timer_t *timer);
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 extern int mb_tman_next_timeout(mb_tman_t *tman,
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
28 const mb_timeval_t *now,
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
29 mb_timeval_t *tmo_after);
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
30 extern int mb_tman_handle_timeout(mb_tman_t *tman, mb_timeval_t *now);
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
32 #define MB_TIMEVAL_SET(_tv, _sec, _usec) \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
33 do { \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
34 (_tv)->tv_sec = _sec; \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
35 (_tv)->tv_usec = _usec; \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
36 } while(0)
43
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
37 #define MB_TIMEVAL_CP(_tv1, _tv2) \
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
38 do { \
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
39 (_tv1)->tv_sec = (_tv2)->tv_sec; \
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
40 (_tv1)->tv_usec = (_tv2)->tv_usec; \
6270230b9248 Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents: 41
diff changeset
41 } while(0)
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
42 #define MB_TIMEVAL_SEC(_tv) ((_tv)->tv_sec)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
43 #define MB_TIMEVAL_USEC(_tv) ((_tv)->tv_usec)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
44 #define MB_TIMEVAL_LATER(a, b) \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
45 ((a)->tv_sec > (b)->tv_sec || \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
46 ((a)->tv_sec == (b)->tv_sec && \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
47 (a)->tv_usec > (b)->tv_usec))
46
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
48 #define MB_TIMEVAL_LATER_INC(a, b) \
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
49 ((a)->tv_sec > (b)->tv_sec || \
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
50 ((a)->tv_sec == (b)->tv_sec && \
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
51 (a)->tv_usec >= (b)->tv_usec))
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
52 #define MB_TIMEVAL_EQ(a, b) \
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
53 ((a)->tv_sec == (b)->tv_sec && \
46b77c92d118 Rewrite mb_progm_step()
Thinker K.F. Li <thinker@branda.to>
parents: 43
diff changeset
54 (a)->tv_usec == (b)->tv_usec)
41
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
55 #define MB_TIMEVAL_DIFF(a, b) \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
56 do { \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
57 (a)->tv_sec -= (b)->tv_sec; \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
58 if((a)->tv_usec < (b)->tv_usec) { \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
59 (a)->tv_sec--; \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
60 (a)->tv_usec += 1000000; \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
61 } \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
62 (a)->tv_usec -= (b)->tv_usec; \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
63 } while(0)
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
64 #define MB_TIMEVAL_ADD(a, b) \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
65 do { \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
66 (a)->tv_sec += (b)->tv_sec; \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
67 (a)->tv_usec += (b)->tv_usec; \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
68 if((a)->tv_usec >= 1000000) { \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
69 (a)->tv_sec++; \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
70 (a)->tv_usec -= 1000000; \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
71 } \
400b4b5db0dc Working on animation
Thinker K.F. Li <thinker@branda.to>
parents: 39
diff changeset
72 } while(0)
39
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74
db2aa914e14b timer for animation
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 #endif /* __MB_TIMER_H_ */