src/server/daemon/event_linux.c

changeset 552
4ed0e46aa9dc
parent 547
280bf87c8689
equal deleted inserted replaced
551:97039494764b 552:4ed0e46aa9dc
29 #include <stdio.h> 29 #include <stdio.h>
30 #include <stdlib.h> 30 #include <stdlib.h>
31 #include <errno.h> 31 #include <errno.h>
32 #include <sys/epoll.h> 32 #include <sys/epoll.h>
33 #include <sys/eventfd.h> 33 #include <sys/eventfd.h>
34 #include <signal.h>
34 35
35 #include <cx/array_list.h> 36 #include <cx/array_list.h>
36 #include <cx/linked_list.h> 37 #include <cx/linked_list.h>
37 38
38 #include "../util/systhr.h" 39 #include "../util/systhr.h"
90 if(epoll_ctl(handler->ep, EPOLL_CTL_ADD, handler->event_fd, &epev)) { 91 if(epoll_ctl(handler->ep, EPOLL_CTL_ADD, handler->event_fd, &epev)) {
91 log_ereport(LOG_FAILURE, "evhandler_create: epoll_ctl: %s", strerror(errno)); 92 log_ereport(LOG_FAILURE, "evhandler_create: epoll_ctl: %s", strerror(errno));
92 return NULL; 93 return NULL;
93 } 94 }
94 95
95 SYS_THREAD t = systhread_start( 96 handler->thr = systhread_start(
96 0, 97 0,
97 0, 98 0,
98 (thrstartfunc)ev_handle_events, 99 (thrstartfunc)ev_handle_events,
99 handler); 100 handler);
100 systhread_detach(t);
101 } 101 }
102 102
103 return ev; 103 return ev;
104 }
105
106 void ev_instance_wait(EventHandler *h) {
107 EventHandlerLinux *ev = (EventHandlerLinux*)h;
108 void *ret;
109 pthread_join(ev->thr, &ret);
104 } 110 }
105 111
106 static volatile int ev_close = 0; 112 static volatile int ev_close = 0;
107 113
108 void ev_instance_close(EventHandler *h) { 114 void ev_instance_close(EventHandler *h) {
252 if(ret == 0 || ++loop_ctn >= EV_IDLE_LOOP_CTN) { 258 if(ret == 0 || ++loop_ctn >= EV_IDLE_LOOP_CTN) {
253 watchlist_check(&ev->base, 0); 259 watchlist_check(&ev->base, 0);
254 loop_ctn = 0; 260 loop_ctn = 0;
255 } 261 }
256 } 262 }
257 263
258 // epoll fd is already closed 264 // epoll fd is already closed
259 265
260 ev_queue_free(ev->queue_begin); 266 ev_queue_free(ev->queue_begin);
261 pthread_mutex_destroy(&ev->queue_lock); 267 pthread_mutex_destroy(&ev->queue_lock);
262 close(ev->event_fd); 268 close(ev->event_fd);

mercurial