… | |
… | |
30 | */ |
30 | */ |
31 | |
31 | |
32 | #include <stddef.h> |
32 | #include <stddef.h> |
33 | #include <stdlib.h> |
33 | #include <stdlib.h> |
34 | #include <sys/time.h> |
34 | #include <sys/time.h> |
|
|
35 | #include <assert.h> |
35 | |
36 | |
|
|
37 | #ifndef EV_EMBED |
36 | #include "event.h" |
38 | # include "event.h" |
|
|
39 | #endif |
37 | |
40 | |
38 | #if EV_MULTIPLICITY |
41 | #if EV_MULTIPLICITY |
39 | # define dLOOPev struct ev_loop *loop = (struct ev_loop *)ev->ev_base |
42 | # define dLOOPev struct ev_loop *loop = (struct ev_loop *)ev->ev_base |
40 | # define dLOOPbase struct ev_loop *loop = (struct ev_loop *)base |
43 | # define dLOOPbase struct ev_loop *loop = (struct ev_loop *)base |
41 | #else |
44 | #else |
… | |
… | |
47 | struct event_base |
50 | struct event_base |
48 | { |
51 | { |
49 | int dummy; |
52 | int dummy; |
50 | }; |
53 | }; |
51 | |
54 | |
52 | static struct event_base x_base, *x_cur; |
55 | static struct event_base *x_cur; |
53 | |
56 | |
54 | static void |
57 | static void |
55 | tv_set (struct timeval *tv, ev_tstamp at) |
58 | tv_set (struct timeval *tv, ev_tstamp at) |
56 | { |
59 | { |
57 | tv->tv_sec = (long)at; |
60 | tv->tv_sec = (long)at; |
… | |
… | |
80 | } |
83 | } |
81 | |
84 | |
82 | void *event_init (void) |
85 | void *event_init (void) |
83 | { |
86 | { |
84 | #if EV_MULTIPLICITY |
87 | #if EV_MULTIPLICITY |
|
|
88 | if (x_cur) |
85 | x_cur = (struct event_base *)ev_loop_new (EVMETHOD_AUTO); |
89 | x_cur = (struct event_base *)ev_loop_new (EVMETHOD_AUTO); |
|
|
90 | else |
|
|
91 | x_cur = ev_default_loop (EVMETHOD_AUTO); |
86 | #else |
92 | #else |
87 | x_cur = &x_base; |
93 | assert (("multiple event bases not supported when not compiled with EV_MULTIPLICITY", !x_cur)); |
|
|
94 | |
|
|
95 | x_cur = (struct event_base *)ev_default_loop (EVMETHOD_AUTO); |
88 | #endif |
96 | #endif |
89 | |
97 | |
90 | return x_cur; |
98 | return x_cur; |
91 | } |
99 | } |
92 | |
100 | |
… | |
… | |
102 | int event_dispatch (void) |
110 | int event_dispatch (void) |
103 | { |
111 | { |
104 | return event_base_dispatch (x_cur); |
112 | return event_base_dispatch (x_cur); |
105 | } |
113 | } |
106 | |
114 | |
107 | #ifdef EV_STANDALONE |
115 | #ifdef EV_EMBED |
108 | void event_set_log_callback (event_log_cb cb) |
116 | void event_set_log_callback (event_log_cb cb) |
109 | { |
117 | { |
110 | /* nop */ |
118 | /* nop */ |
111 | } |
119 | } |
112 | #endif |
120 | #endif |