From: Bernhard Froehlich Date: Sat, 4 May 2013 14:50:45 +0000 (+0200) Subject: Add kqueue support and make epoll optional. X-Git-Tag: v3.9~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=303f92a61bfbea86e8cb4e184fb439e7d607634e;p=thirdparty%2Ftvheadend.git Add kqueue support and make epoll optional. --- diff --git a/src/timeshift/timeshift_reader.c b/src/timeshift/timeshift_reader.c index e9b3ca539..bbf3bf741 100644 --- a/src/timeshift/timeshift_reader.c +++ b/src/timeshift/timeshift_reader.c @@ -29,6 +29,13 @@ #include #include +#ifdef ENABLE_EPOLL +#include +#elif ENABLE_KQUEUE +#include +#include +#endif + /* ************************************************************************** * File Reading * *************************************************************************/ @@ -399,7 +406,7 @@ static int _timeshift_flush_to_live void *timeshift_reader ( void *p ) { timeshift_t *ts = p; - int efd, nfds, end, fd = -1, run = 1, wait = -1; + int nfds, end, fd = -1, run = 1, wait = -1; timeshift_file_t *cur_file = NULL; off_t cur_off = 0; int cur_speed = 100, keyframe_mode = 0; @@ -409,13 +416,26 @@ void *timeshift_reader ( void *p ) timeshift_index_iframe_t *tsi = NULL; streaming_skip_t *skip = NULL; time_t last_status = 0; +#ifdef ENABLE_EPOLL + int efd; + struct epoll_event ev = { 0 }; +#elif ENABLE_KQUEUE + int kfd; + struct kevent ke; +#endif +#ifdef ENABLE_EPOLL /* Poll */ - struct epoll_event ev = { 0 }; efd = epoll_create(1); ev.events = EPOLLIN; ev.data.fd = ts->rd_pipe.rd; epoll_ctl(efd, EPOLL_CTL_ADD, ev.data.fd, &ev); +#elif ENABLE_KQUEUE + /* kqueue */ + kfd = kqueue(); + EV_SET(&ke, ts->rd_pipe.rd, EVFILT_READ, EV_ADD, 0, 0, NULL); + kevent(kfd, &ke, 1, NULL, 0, NULL); +#endif /* Output */ while (run) { @@ -427,7 +447,11 @@ void *timeshift_reader ( void *p ) /* Wait for data */ if(wait) +#ifdef ENABLE_EPOLL nfds = epoll_wait(efd, &ev, 1, wait); +#elif ENABLE_KQUEUE + nfds = kevent(kfd, NULL, 0, &ke, 1, NULL); +#endif else nfds = 0; wait = -1; @@ -438,7 +462,7 @@ void *timeshift_reader ( void *p ) /* Control */ pthread_mutex_lock(&ts->state_mutex); if (nfds == 1) { - if (_read_msg(ev.data.fd, &ctrl) > 0) { + if (_read_msg(ts->rd_pipe.rd, &ctrl) > 0) { /* Exit */ if (ctrl->sm_type == SMT_EXIT) { @@ -802,6 +826,11 @@ void *timeshift_reader ( void *p ) } /* Cleanup */ +#ifdef ENABLE_EPOLL + close(efd); +#elif ENABLE_KQUEUE + close(kfd); +#endif if (fd != -1) close(fd); if (sm) streaming_msg_free(sm); if (ctrl) streaming_msg_free(ctrl);