… | |
… | |
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 | #include "ev.h" |
36 | #include "event.h" |
38 | #include "event.h" |
37 | |
39 | |
38 | #if EV_MULTIPLICITY |
40 | #if EV_MULTIPLICITY |
39 | # define dLOOPev struct ev_loop *loop = (struct ev_loop *)ev->ev_base |
41 | # define dLOOPev struct ev_loop *loop = (struct ev_loop *)ev->ev_base |
40 | # define dLOOPbase struct ev_loop *loop = (struct ev_loop *)base |
42 | # define dLOOPbase struct ev_loop *loop = (struct ev_loop *)base |
… | |
… | |
47 | struct event_base |
49 | struct event_base |
48 | { |
50 | { |
49 | int dummy; |
51 | int dummy; |
50 | }; |
52 | }; |
51 | |
53 | |
52 | static struct event_base x_base, *x_cur; |
54 | static struct event_base *x_cur; |
53 | |
55 | |
54 | static void |
56 | static void |
55 | tv_set (struct timeval *tv, ev_tstamp at) |
57 | tv_set (struct timeval *tv, ev_tstamp at) |
56 | { |
58 | { |
57 | tv->tv_sec = (long)at; |
59 | tv->tv_sec = (long)at; |
… | |
… | |
80 | } |
82 | } |
81 | |
83 | |
82 | void *event_init (void) |
84 | void *event_init (void) |
83 | { |
85 | { |
84 | #if EV_MULTIPLICITY |
86 | #if EV_MULTIPLICITY |
|
|
87 | if (x_cur) |
85 | x_cur = (struct event_base *)ev_loop_new (EVMETHOD_AUTO); |
88 | x_cur = (struct event_base *)ev_loop_new (EVMETHOD_AUTO); |
|
|
89 | else |
|
|
90 | x_cur = (struct event_base *)ev_default_loop (EVMETHOD_AUTO); |
86 | #else |
91 | #else |
87 | x_cur = &x_base; |
92 | assert (("multiple event bases not supported when not compiled with EV_MULTIPLICITY", !x_cur)); |
|
|
93 | |
|
|
94 | x_cur = (struct event_base *)ev_default_loop (EVMETHOD_AUTO); |
88 | #endif |
95 | #endif |
89 | |
96 | |
90 | return x_cur; |
97 | return x_cur; |
91 | } |
98 | } |
92 | |
99 | |
93 | void event_base_free (struct event_base *base) |
100 | void event_base_free (struct event_base *base) |
94 | { |
101 | { |
95 | dLOOPbase; |
102 | dLOOPbase; |
96 | |
103 | |
97 | #if EV_MULTIPLICITY |
104 | #if EV_MULTIPLICITY |
|
|
105 | if (ev_default_loop (EVMETHOD_AUTO) != loop) |
98 | ev_loop_delete (loop); |
106 | ev_loop_destroy (loop); |
99 | #endif |
107 | #endif |
100 | } |
108 | } |
101 | |
109 | |
102 | int event_dispatch (void) |
110 | int event_dispatch (void) |
103 | { |
111 | { |
… | |
… | |
345 | return 0; |
353 | return 0; |
346 | } |
354 | } |
347 | |
355 | |
348 | int event_base_priority_init (struct event_base *base, int npri) |
356 | int event_base_priority_init (struct event_base *base, int npri) |
349 | { |
357 | { |
350 | dLOOPbase; |
358 | /*dLOOPbase;*/ |
351 | |
359 | |
352 | return 0; |
360 | return 0; |
353 | } |
361 | } |
354 | |
362 | |