24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
27 */ |
27 */ |
28 |
28 |
29 #include <ucx/map.h> |
29 #include "../../ucx/map.h" |
|
30 #include "../util/atomic.h" |
30 |
31 |
31 #include "event.h" |
32 #include "event.h" |
32 |
33 |
33 UcxMap *event_handler_map = NULL; |
34 UcxMap *event_handler_map = NULL; |
34 int numevhandlers = 0; |
35 int numevhandlers = 0; |
35 |
36 |
36 event_handler_t *default_event_handler = NULL; |
37 EVHandler *default_event_handler = NULL; |
37 |
38 |
38 event_handler_t *last_handler_c = NULL; |
39 EVHandler *last_handler_c = NULL; |
39 |
40 |
40 int create_event_handler(EventHandlerConfig *cfg) { |
41 int create_event_handler(EventHandlerConfig *cfg) { |
41 if(event_handler_map == NULL) { |
42 if(event_handler_map == NULL) { |
42 event_handler_map = ucx_map_new(16); |
43 event_handler_map = ucx_map_new(16); |
43 } |
44 } |
93 |
94 |
94 return create_event_handler(&cfg); |
95 return create_event_handler(&cfg); |
95 } |
96 } |
96 |
97 |
97 |
98 |
98 event_handler_t* get_default_event_handler() { |
99 EVHandler* get_default_event_handler() { |
99 return default_event_handler; |
100 return default_event_handler; |
100 } |
101 } |
101 |
102 |
102 event_handler_t* get_event_handler(char *name) { |
103 EVHandler* get_event_handler(char *name) { |
103 return ucx_map_cstr_get(event_handler_map, name); |
104 return ucx_map_cstr_get(event_handler_map, name); |
104 } |
105 } |
|
106 |
|
107 EventHandler* ev_instance(EVHandler *ev) { |
|
108 int nev = ev->numins; |
|
109 if(nev == 1) { |
|
110 return ev->instances[0]; |
|
111 } |
|
112 |
|
113 int ins = ev->current & nev; |
|
114 ws_atomic_inc32(&ev->current); |
|
115 return ev->instances[ins]; |
|
116 } |