]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Add kqueue support and make epoll optional.
authorBernhard Froehlich <decke@bluelife.at>
Sat, 4 May 2013 14:50:45 +0000 (16:50 +0200)
committerUser Decke <decke@bluelife.at>
Wed, 8 May 2013 13:19:39 +0000 (15:19 +0200)
src/timeshift/timeshift_reader.c

index e9b3ca5391a1bfefc0cae88e23357abb38116bc6..bbf3bf741a98d6e14a1b10bac3e126e2fd7d63ba 100644 (file)
 #include <string.h>
 #include <assert.h>
 
+#ifdef ENABLE_EPOLL
+#include <sys/epoll.h>
+#elif ENABLE_KQUEUE
+#include <sys/event.h>
+#include <sys/time.h>
+#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);