1 /* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 * 4 * Copyright 2013 Olaf Wintermann. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 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 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndefEVENT_LINUX_H 30 #defineEVENT_LINUX_H 31 32 #include"event.h" 33 #include<inttypes.h> 34 35 #include<cx/list.h> 36 37 #ifdef __cplusplus
38 extern"C" {
39 #endif 40 41 #defineEV_QUEUE_RESERVE8 42 43 typedefstruct EventQueue EventQueue;
44 45 typedefstruct EventHandlerLinux {
46 /* 47 * base eventhandler elements (fnreturn, watchlist) 48 */ 49 EventHandler base;
50 51 /* 52 * eventhandler thread 53 */ 54 pthread_t thr;
55 56 /* 57 * epoll fd 58 */ 59 int ep;
60 61 /* 62 * eventfd for notifying that new elements 63 * in the event_queue are available 64 */ 65 int event_fd;
66 67 /* 68 * queue for custom events (event_send) 69 * each block can contain up to EV_MAX_EVENTS events 70 * the event loop should not retrieve more than one block 71 * 72 * first queue block 73 */ 74 EventQueue *queue_begin;
75 76 /* 77 * last queue block 78 */ 79 EventQueue *queue_end;
80 81 /* 82 * allocated unused blocks 83 */ 84 EventQueue *reserve_block[EV_QUEUE_RESERVE];
85 86 /* 87 * number of unused blocks 88 */ 89 size_t num_reserve;
90 91 /* 92 * mutex for event_queue 93 */ 94 pthread_mutex_t queue_lock;
95 } EventHandlerLinux;
96 97 struct EventQueue {
98 /* 99 * array of events100 */101 Event *events[EV_MAX_EVENTS];
102 /*103 * number of events104 */105 size_t numevents;
106 /*107 * next event block108 */109 EventQueue *next;
110 };
111 112 void ev_handle_events(EventHandlerLinux *ev);
113 114 int ev_convert2sys_events(int events);
115 116 void ev_queue_free(EventQueue *queue);
117 118 #ifdef __cplusplus
119 }
120 #endif121 122 #endif/* EVENT_LINUX_H */123 124