Mercurial > MadButterfly
annotate include/mb_timer.h @ 982:1bda9f9e00ea
Set the inkscape:groupmode attribute so that the inkscape will put the scene groups in the layer manager and protect it from detection.
author | wycc |
---|---|
date | Sun, 21 Nov 2010 08:43:02 +0800 |
parents | 586e50f82c1f |
children |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
186
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
186
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
39 | 3 #ifndef __MB_TIMER_H_ |
4 #define __MB_TIMER_H_ | |
5 | |
41 | 6 #include <sys/time.h> |
59 | 7 #include <stdint.h> |
41 | 8 |
39 | 9 typedef uint32_t mbsec_t; |
10 typedef uint32_t mbusec_t; | |
11 typedef struct _mb_timer mb_timer_t; | |
12 typedef struct _mb_tman mb_tman_t; | |
41 | 13 typedef struct timeval mb_timeval_t; |
39 | 14 |
41 | 15 |
16 typedef void (*mb_tmo_hdlr)(const mb_timeval_t *tmo, | |
17 const mb_timeval_t *now, | |
39 | 18 void *arg); |
19 | |
20 extern mb_tman_t *mb_tman_new(void); | |
21 extern void mb_tman_free(mb_tman_t *tman); | |
22 extern mb_timer_t *mb_tman_timeout(mb_tman_t *tman, | |
41 | 23 const mb_timeval_t *tmo, |
39 | 24 mb_tmo_hdlr hdlr, void *arg); |
25 extern int mb_tman_remove(mb_tman_t *tman, mb_timer_t *timer); | |
26 extern int mb_tman_next_timeout(mb_tman_t *tman, | |
41 | 27 const mb_timeval_t *now, |
28 mb_timeval_t *tmo_after); | |
29 extern int mb_tman_handle_timeout(mb_tman_t *tman, mb_timeval_t *now); | |
39 | 30 |
41 | 31 #define MB_TIMEVAL_SET(_tv, _sec, _usec) \ |
32 do { \ | |
33 (_tv)->tv_sec = _sec; \ | |
34 (_tv)->tv_usec = _usec; \ | |
35 } while(0) | |
43
6270230b9248
Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents:
41
diff
changeset
|
36 #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
|
37 do { \ |
6270230b9248
Use MB_TIMEVAL_CP() instead of memcpy
Thinker K.F. Li <thinker@branda.to>
parents:
41
diff
changeset
|
38 (_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
|
39 (_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
|
40 } while(0) |
41 | 41 #define MB_TIMEVAL_SEC(_tv) ((_tv)->tv_sec) |
42 #define MB_TIMEVAL_USEC(_tv) ((_tv)->tv_usec) | |
43 #define MB_TIMEVAL_LATER(a, b) \ | |
44 ((a)->tv_sec > (b)->tv_sec || \ | |
45 ((a)->tv_sec == (b)->tv_sec && \ | |
46 (a)->tv_usec > (b)->tv_usec)) | |
46 | 47 #define MB_TIMEVAL_LATER_INC(a, b) \ |
48 ((a)->tv_sec > (b)->tv_sec || \ | |
49 ((a)->tv_sec == (b)->tv_sec && \ | |
50 (a)->tv_usec >= (b)->tv_usec)) | |
51 #define MB_TIMEVAL_EQ(a, b) \ | |
52 ((a)->tv_sec == (b)->tv_sec && \ | |
53 (a)->tv_usec == (b)->tv_usec) | |
41 | 54 #define MB_TIMEVAL_DIFF(a, b) \ |
55 do { \ | |
56 (a)->tv_sec -= (b)->tv_sec; \ | |
57 if((a)->tv_usec < (b)->tv_usec) { \ | |
58 (a)->tv_sec--; \ | |
59 (a)->tv_usec += 1000000; \ | |
60 } \ | |
61 (a)->tv_usec -= (b)->tv_usec; \ | |
62 } while(0) | |
63 #define MB_TIMEVAL_ADD(a, b) \ | |
64 do { \ | |
65 (a)->tv_sec += (b)->tv_sec; \ | |
66 (a)->tv_usec += (b)->tv_usec; \ | |
67 if((a)->tv_usec >= 1000000) { \ | |
68 (a)->tv_sec++; \ | |
69 (a)->tv_usec -= 1000000; \ | |
70 } \ | |
71 } while(0) | |
155
6749f6639924
Fix bug for STAILQ that fail to remove a node.
Thinker K.F. Li <thinker@branda.to>
parents:
77
diff
changeset
|
72 #define MB_TIMEVAL_DIV(a, b) \ |
6749f6639924
Fix bug for STAILQ that fail to remove a node.
Thinker K.F. Li <thinker@branda.to>
parents:
77
diff
changeset
|
73 (((a)->tv_sec * 1000000.0 + (a)->tv_usec) / \ |
6749f6639924
Fix bug for STAILQ that fail to remove a node.
Thinker K.F. Li <thinker@branda.to>
parents:
77
diff
changeset
|
74 ((b)->tv_sec * 1000000.0 + (b)->tv_usec)) |
39 | 75 |
76 | |
77 | 77 extern void get_now(mb_timeval_t *tmo); |
78 | |
79 | |
39 | 80 #endif /* __MB_TIMER_H_ */ |