Mercurial > MadButterfly
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 | 1 #ifndef __MB_TIMER_H_ |
2 #define __MB_TIMER_H_ | |
3 | |
41 | 4 #include <sys/time.h> |
5 | |
60 | 6 #ifdef __linux__ |
7 #include <linux/types.h> | |
8 #endif | |
9 | |
39 | 10 typedef uint32_t mbsec_t; |
11 typedef uint32_t mbusec_t; | |
12 typedef struct _mb_timer mb_timer_t; | |
13 typedef struct _mb_tman mb_tman_t; | |
41 | 14 typedef struct timeval mb_timeval_t; |
39 | 15 |
41 | 16 |
17 typedef void (*mb_tmo_hdlr)(const mb_timeval_t *tmo, | |
18 const mb_timeval_t *now, | |
39 | 19 void *arg); |
20 | |
21 extern mb_tman_t *mb_tman_new(void); | |
22 extern void mb_tman_free(mb_tman_t *tman); | |
23 extern mb_timer_t *mb_tman_timeout(mb_tman_t *tman, | |
41 | 24 const mb_timeval_t *tmo, |
39 | 25 mb_tmo_hdlr hdlr, void *arg); |
26 extern int mb_tman_remove(mb_tman_t *tman, mb_timer_t *timer); | |
27 extern int mb_tman_next_timeout(mb_tman_t *tman, | |
41 | 28 const mb_timeval_t *now, |
29 mb_timeval_t *tmo_after); | |
30 extern int mb_tman_handle_timeout(mb_tman_t *tman, mb_timeval_t *now); | |
39 | 31 |
41 | 32 #define MB_TIMEVAL_SET(_tv, _sec, _usec) \ |
33 do { \ | |
34 (_tv)->tv_sec = _sec; \ | |
35 (_tv)->tv_usec = _usec; \ | |
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 | 42 #define MB_TIMEVAL_SEC(_tv) ((_tv)->tv_sec) |
43 #define MB_TIMEVAL_USEC(_tv) ((_tv)->tv_usec) | |
44 #define MB_TIMEVAL_LATER(a, b) \ | |
45 ((a)->tv_sec > (b)->tv_sec || \ | |
46 ((a)->tv_sec == (b)->tv_sec && \ | |
47 (a)->tv_usec > (b)->tv_usec)) | |
46 | 48 #define MB_TIMEVAL_LATER_INC(a, b) \ |
49 ((a)->tv_sec > (b)->tv_sec || \ | |
50 ((a)->tv_sec == (b)->tv_sec && \ | |
51 (a)->tv_usec >= (b)->tv_usec)) | |
52 #define MB_TIMEVAL_EQ(a, b) \ | |
53 ((a)->tv_sec == (b)->tv_sec && \ | |
54 (a)->tv_usec == (b)->tv_usec) | |
41 | 55 #define MB_TIMEVAL_DIFF(a, b) \ |
56 do { \ | |
57 (a)->tv_sec -= (b)->tv_sec; \ | |
58 if((a)->tv_usec < (b)->tv_usec) { \ | |
59 (a)->tv_sec--; \ | |
60 (a)->tv_usec += 1000000; \ | |
61 } \ | |
62 (a)->tv_usec -= (b)->tv_usec; \ | |
63 } while(0) | |
64 #define MB_TIMEVAL_ADD(a, b) \ | |
65 do { \ | |
66 (a)->tv_sec += (b)->tv_sec; \ | |
67 (a)->tv_usec += (b)->tv_usec; \ | |
68 if((a)->tv_usec >= 1000000) { \ | |
69 (a)->tv_sec++; \ | |
70 (a)->tv_usec -= 1000000; \ | |
71 } \ | |
72 } while(0) | |
39 | 73 |
74 | |
75 #endif /* __MB_TIMER_H_ */ |