Diff for /libaitsched/src/hooks.c between versions 1.27.2.3 and 1.27.2.5

version 1.27.2.3, 2014/05/21 22:09:01 version 1.27.2.5, 2014/05/21 23:05:43
Line 62  sched_hook_init(void *root, void *arg __unused) Line 62  sched_hook_init(void *root, void *arg __unused)
         if (!r)          if (!r)
                 return (void*) -1;                  return (void*) -1;
   
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         r->root_kq = kqueue();          r->root_kq = kqueue();
         if (r->root_kq == -1) {          if (r->root_kq == -1) {
                 LOGERR;                  LOGERR;
                 return (void*) -1;                  return (void*) -1;
         }          }
   #elif SUP_ENABLE == EP_SUPPORT
           r->root_kq = epoll_create(KQ_EVENTS);
           if (r->root_kq == -1) {
                   LOGERR;
                   return (void*) -1;
           }
 #else  #else
         r->root_kq ^= r->root_kq;          r->root_kq ^= r->root_kq;
         FD_ZERO(&r->root_fds[0]);          FD_ZERO(&r->root_fds[0]);
Line 92  sched_hook_fini(void *root, void *arg __unused) Line 98  sched_hook_fini(void *root, void *arg __unused)
         if (!r)          if (!r)
                 return (void*) -1;                  return (void*) -1;
   
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT || SUP_ENABLE == EP_SUPPORT
         if (r->root_kq > 2) {          if (r->root_kq > 2) {
                 close(r->root_kq);                  close(r->root_kq);
                 r->root_kq = 0;                  r->root_kq = 0;
Line 117  void * Line 123  void *
 sched_hook_cancel(void *task, void *arg __unused)  sched_hook_cancel(void *task, void *arg __unused)
 {  {
         sched_task_t *t = task;          sched_task_t *t = task;
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         struct kevent chg[1];          struct kevent chg[1];
         struct timespec timeout = { 0, 0 };          struct timespec timeout = { 0, 0 };
 #else  #else
         sched_root_task_t *r = NULL;          sched_root_task_t *r = NULL;
        register int i;        register int i = -1;
 #endif  #endif
 #ifdef AIO_SUPPORT  #ifdef AIO_SUPPORT
         struct aiocb *acb;          struct aiocb *acb;
Line 134  sched_hook_cancel(void *task, void *arg __unused) Line 140  sched_hook_cancel(void *task, void *arg __unused)
   
         if (!t || !TASK_ROOT(t))          if (!t || !TASK_ROOT(t))
                 return (void*) -1;                  return (void*) -1;
#if SUP_ENABLE != KQ_ENABLE#if SUP_ENABLE != KQ_SUPPORT
         r = TASK_ROOT(t);          r = TASK_ROOT(t);
 #endif  #endif
   
         switch (TASK_TYPE(t)) {          switch (TASK_TYPE(t)) {
                 case taskREAD:                  case taskREAD:
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
 #ifdef __NetBSD__  #ifdef __NetBSD__
                         EV_SET(&chg[0], TASK_FD(t), EVFILT_READ, EV_DELETE, 0, 0, (intptr_t) TASK_FD(t));                          EV_SET(&chg[0], TASK_FD(t), EVFILT_READ, EV_DELETE, 0, 0, (intptr_t) TASK_FD(t));
 #else  #else
                         EV_SET(&chg[0], TASK_FD(t), EVFILT_READ, EV_DELETE, 0, 0, (void*) TASK_FD(t));                          EV_SET(&chg[0], TASK_FD(t), EVFILT_READ, EV_DELETE, 0, 0, (void*) TASK_FD(t));
 #endif  #endif
   #elif SUP_ENABLE == EP_SUPPORT
                           i = TASK_FD(t);
 #else  #else
                         FD_CLR(TASK_FD(t), &r->root_fds[0]);                          FD_CLR(TASK_FD(t), &r->root_fds[0]);
   
Line 158  sched_hook_cancel(void *task, void *arg __unused) Line 166  sched_hook_cancel(void *task, void *arg __unused)
 #endif  #endif
                         break;                          break;
                 case taskWRITE:                  case taskWRITE:
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
 #ifdef __NetBSD__  #ifdef __NetBSD__
                         EV_SET(&chg[0], TASK_FD(t), EVFILT_WRITE, EV_DELETE, 0, 0, (intptr_t) TASK_FD(t));                          EV_SET(&chg[0], TASK_FD(t), EVFILT_WRITE, EV_DELETE, 0, 0, (intptr_t) TASK_FD(t));
 #else  #else
                         EV_SET(&chg[0], TASK_FD(t), EVFILT_WRITE, EV_DELETE, 0, 0, (void*) TASK_FD(t));                          EV_SET(&chg[0], TASK_FD(t), EVFILT_WRITE, EV_DELETE, 0, 0, (void*) TASK_FD(t));
 #endif  #endif
   #elif SUP_ENABLE == EP_SUPPORT
                           i = TASK_FD(t);
 #else  #else
                         FD_CLR(TASK_FD(t), &r->root_fds[1]);                          FD_CLR(TASK_FD(t), &r->root_fds[1]);
   
Line 176  sched_hook_cancel(void *task, void *arg __unused) Line 186  sched_hook_cancel(void *task, void *arg __unused)
 #endif  #endif
                         break;                          break;
                 case taskALARM:                  case taskALARM:
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
 #ifdef __NetBSD__  #ifdef __NetBSD__
                         EV_SET(&chg[0], (uintptr_t) TASK_DATA(t), EVFILT_TIMER, EV_DELETE,                           EV_SET(&chg[0], (uintptr_t) TASK_DATA(t), EVFILT_TIMER, EV_DELETE, 
                                         0, 0, (intptr_t) TASK_DATA(t));                                          0, 0, (intptr_t) TASK_DATA(t));
Line 187  sched_hook_cancel(void *task, void *arg __unused) Line 197  sched_hook_cancel(void *task, void *arg __unused)
 #endif  #endif
                         break;                          break;
                 case taskNODE:                  case taskNODE:
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
 #ifdef __NetBSD__  #ifdef __NetBSD__
                         EV_SET(&chg[0], TASK_FD(t), EVFILT_VNODE, EV_DELETE, 0, 0, (intptr_t) TASK_FD(t));                          EV_SET(&chg[0], TASK_FD(t), EVFILT_VNODE, EV_DELETE, 0, 0, (intptr_t) TASK_FD(t));
 #else  #else
Line 196  sched_hook_cancel(void *task, void *arg __unused) Line 206  sched_hook_cancel(void *task, void *arg __unused)
 #endif  #endif
                         break;                          break;
                 case taskPROC:                  case taskPROC:
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
 #ifdef __NetBSD__  #ifdef __NetBSD__
                         EV_SET(&chg[0], TASK_VAL(t), EVFILT_PROC, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t));                          EV_SET(&chg[0], TASK_VAL(t), EVFILT_PROC, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t));
 #else  #else
Line 205  sched_hook_cancel(void *task, void *arg __unused) Line 215  sched_hook_cancel(void *task, void *arg __unused)
 #endif  #endif
                         break;                          break;
                 case taskSIGNAL:                  case taskSIGNAL:
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
 #ifdef __NetBSD__  #ifdef __NetBSD__
                         EV_SET(&chg[0], TASK_VAL(t), EVFILT_SIGNAL, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t));                          EV_SET(&chg[0], TASK_VAL(t), EVFILT_SIGNAL, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t));
 #else  #else
Line 217  sched_hook_cancel(void *task, void *arg __unused) Line 227  sched_hook_cancel(void *task, void *arg __unused)
                         break;                          break;
 #ifdef AIO_SUPPORT  #ifdef AIO_SUPPORT
                 case taskAIO:                  case taskAIO:
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
 #ifdef __NetBSD__  #ifdef __NetBSD__
                         EV_SET(&chg[0], TASK_VAL(t), EVFILT_AIO, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t));                          EV_SET(&chg[0], TASK_VAL(t), EVFILT_AIO, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t));
 #else  #else
Line 234  sched_hook_cancel(void *task, void *arg __unused) Line 244  sched_hook_cancel(void *task, void *arg __unused)
                         break;                          break;
 #ifdef EVFILT_LIO  #ifdef EVFILT_LIO
                 case taskLIO:                  case taskLIO:
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
 #ifdef __NetBSD__  #ifdef __NetBSD__
                         EV_SET(&chg[0], TASK_VAL(t), EVFILT_LIO, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t));                          EV_SET(&chg[0], TASK_VAL(t), EVFILT_LIO, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t));
 #else  #else
Line 256  sched_hook_cancel(void *task, void *arg __unused) Line 266  sched_hook_cancel(void *task, void *arg __unused)
 #endif  /* AIO_SUPPORT */  #endif  /* AIO_SUPPORT */
 #ifdef EVFILT_USER  #ifdef EVFILT_USER
                 case taskUSER:                  case taskUSER:
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
 #ifdef __NetBSD__  #ifdef __NetBSD__
                         EV_SET(&chg[0], TASK_VAL(t), EVFILT_USER, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t));                          EV_SET(&chg[0], TASK_VAL(t), EVFILT_USER, EV_DELETE, 0, 0, (intptr_t) TASK_VAL(t));
 #else  #else
Line 281  sched_hook_cancel(void *task, void *arg __unused) Line 291  sched_hook_cancel(void *task, void *arg __unused)
                         return NULL;                          return NULL;
         }          }
   
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         kevent(TASK_ROOT(t)->root_kq, chg, 1, NULL, 0, &timeout);          kevent(TASK_ROOT(t)->root_kq, chg, 1, NULL, 0, &timeout);
   #elif SUP_ENABLE == EP_SUPPORT
           if (i != -1)
                   epoll_ctl(TASK_ROOT(t)->root_kq, EPOLL_CTL_DEL, i, NULL);
 #endif  #endif
         return NULL;          return NULL;
 }  }
Line 334  void * Line 347  void *
 sched_hook_read(void *task, void *arg __unused)  sched_hook_read(void *task, void *arg __unused)
 {  {
         sched_task_t *t = task;          sched_task_t *t = task;
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         struct kevent chg[1];          struct kevent chg[1];
         struct timespec timeout = { 0, 0 };          struct timespec timeout = { 0, 0 };
   #elif SUP_ENABLE == EP_SUPPORT
           struct epoll_event ee = { .events = EPOLLIN | EPOLLPRI | EPOLLRDHUP, .data.fd = 0 };
 #else  #else
         sched_root_task_t *r = NULL;          sched_root_task_t *r = NULL;
 #endif  #endif
   
         if (!t || !TASK_ROOT(t))          if (!t || !TASK_ROOT(t))
                 return (void*) -1;                  return (void*) -1;
 #if SUP_ENABLE != KQ_ENABLE  
         r = TASK_ROOT(t);  
 #endif  
   
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
 #ifdef __NetBSD__  #ifdef __NetBSD__
         EV_SET(&chg[0], TASK_FD(t), EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, (intptr_t) TASK_FD(t));          EV_SET(&chg[0], TASK_FD(t), EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, (intptr_t) TASK_FD(t));
 #else  #else
Line 360  sched_hook_read(void *task, void *arg __unused) Line 372  sched_hook_read(void *task, void *arg __unused)
                         LOGERR;                          LOGERR;
                 return (void*) -1;                  return (void*) -1;
         }          }
   #elif SUP_ENABLE == EP_SUPPORT
           ee.data.fd = TASK_FD(t);
           if (epoll_ctl(TASK_ROOT(t)->root_kq, EPOLL_CTL_ADD, TASK_FD(t), &ee) == -1) {
                   if (TASK_ROOT(t)->root_hooks.hook_exec.exception)
                           TASK_ROOT(t)->root_hooks.hook_exec.exception(TASK_ROOT(t), NULL);
                   else
                           LOGERR;
                   return (void*) -1;
           }
 #else  #else
           r = TASK_ROOT(t);
         FD_SET(TASK_FD(t), &r->root_fds[0]);          FD_SET(TASK_FD(t), &r->root_fds[0]);
         if (TASK_FD(t) >= r->root_kq)          if (TASK_FD(t) >= r->root_kq)
                 r->root_kq = TASK_FD(t) + 1;                  r->root_kq = TASK_FD(t) + 1;
Line 380  void * Line 402  void *
 sched_hook_write(void *task, void *arg __unused)  sched_hook_write(void *task, void *arg __unused)
 {  {
         sched_task_t *t = task;          sched_task_t *t = task;
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         struct kevent chg[1];          struct kevent chg[1];
         struct timespec timeout = { 0, 0 };          struct timespec timeout = { 0, 0 };
   #elif SUP_ENABLE == EP_SUPPORT
           struct epoll_event ee = { .events = EPOLLOUT, .data.fd = 0 };
 #else  #else
         sched_root_task_t *r = NULL;          sched_root_task_t *r = NULL;
 #endif  #endif
   
         if (!t || !TASK_ROOT(t))          if (!t || !TASK_ROOT(t))
                 return (void*) -1;                  return (void*) -1;
 #if SUP_ENABLE != KQ_ENABLE  
         r = TASK_ROOT(t);  
 #endif  
   
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
 #ifdef __NetBSD__  #ifdef __NetBSD__
         EV_SET(&chg[0], TASK_FD(t), EVFILT_WRITE, EV_ADD | EV_CLEAR, 0, 0, (intptr_t) TASK_FD(t));          EV_SET(&chg[0], TASK_FD(t), EVFILT_WRITE, EV_ADD | EV_CLEAR, 0, 0, (intptr_t) TASK_FD(t));
 #else  #else
Line 406  sched_hook_write(void *task, void *arg __unused) Line 427  sched_hook_write(void *task, void *arg __unused)
                         LOGERR;                          LOGERR;
                 return (void*) -1;                  return (void*) -1;
         }          }
   #elif SUP_ENABLE == EP_SUPPORT
           ee.data.fd = TASK_FD(t);
           if (epoll_ctl(TASK_ROOT(t)->root_kq, EPOLL_CTL_ADD, TASK_FD(t), &ee) == -1) {
                   if (TASK_ROOT(t)->root_hooks.hook_exec.exception)
                           TASK_ROOT(t)->root_hooks.hook_exec.exception(TASK_ROOT(t), NULL);
                   else
                           LOGERR;
                   return (void*) -1;
           }
 #else  #else
           r = TASK_ROOT(t);
         FD_SET(TASK_FD(t), &r->root_fds[1]);          FD_SET(TASK_FD(t), &r->root_fds[1]);
         if (TASK_FD(t) >= r->root_kq)          if (TASK_FD(t) >= r->root_kq)
                 r->root_kq = TASK_FD(t) + 1;                  r->root_kq = TASK_FD(t) + 1;
Line 425  sched_hook_write(void *task, void *arg __unused) Line 456  sched_hook_write(void *task, void *arg __unused)
 void *  void *
 sched_hook_alarm(void *task, void *arg __unused)  sched_hook_alarm(void *task, void *arg __unused)
 {  {
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         sched_task_t *t = task;          sched_task_t *t = task;
         struct kevent chg[1];          struct kevent chg[1];
         struct timespec timeout = { 0, 0 };          struct timespec timeout = { 0, 0 };
Line 464  sched_hook_alarm(void *task, void *arg __unused) Line 495  sched_hook_alarm(void *task, void *arg __unused)
 void *  void *
 sched_hook_node(void *task, void *arg __unused)  sched_hook_node(void *task, void *arg __unused)
 {  {
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         sched_task_t *t = task;          sched_task_t *t = task;
         struct kevent chg[1];          struct kevent chg[1];
         struct timespec timeout = { 0, 0 };          struct timespec timeout = { 0, 0 };
Line 503  sched_hook_node(void *task, void *arg __unused) Line 534  sched_hook_node(void *task, void *arg __unused)
 void *  void *
 sched_hook_proc(void *task, void *arg __unused)  sched_hook_proc(void *task, void *arg __unused)
 {  {
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         sched_task_t *t = task;          sched_task_t *t = task;
         struct kevent chg[1];          struct kevent chg[1];
         struct timespec timeout = { 0, 0 };          struct timespec timeout = { 0, 0 };
Line 540  sched_hook_proc(void *task, void *arg __unused) Line 571  sched_hook_proc(void *task, void *arg __unused)
 void *  void *
 sched_hook_signal(void *task, void *arg __unused)  sched_hook_signal(void *task, void *arg __unused)
 {  {
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         sched_task_t *t = task;          sched_task_t *t = task;
         struct kevent chg[1];          struct kevent chg[1];
         struct timespec timeout = { 0, 0 };          struct timespec timeout = { 0, 0 };
Line 596  sched_hook_signal(void *task, void *arg __unused) Line 627  sched_hook_signal(void *task, void *arg __unused)
 void *  void *
 sched_hook_user(void *task, void *arg __unused)  sched_hook_user(void *task, void *arg __unused)
 {  {
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         sched_task_t *t = task;          sched_task_t *t = task;
         struct kevent chg[1];          struct kevent chg[1];
         struct timespec timeout = { 0, 0 };          struct timespec timeout = { 0, 0 };
Line 637  sched_hook_fetch(void *root, void *arg __unused) Line 668  sched_hook_fetch(void *root, void *arg __unused)
         sched_root_task_t *r = root;          sched_root_task_t *r = root;
         sched_task_t *task, *tmp;          sched_task_t *task, *tmp;
         struct timespec now, m, mtmp;          struct timespec now, m, mtmp;
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         struct kevent evt[1], res[KQ_EVENTS];          struct kevent evt[1], res[KQ_EVENTS];
         struct timespec *timeout;          struct timespec *timeout;
   #elif SUP_ENABLE == EP_SUPPORT
           struct epoll_event res[KQ_EVENTS];
           u_long timeout = 0;
 #else  #else
         struct timeval *timeout, tv;          struct timeval *timeout, tv;
         fd_set rfd, wfd, xfd;          fd_set rfd, wfd, xfd;
Line 735  sched_hook_fetch(void *root, void *arg __unused) Line 769  sched_hook_fetch(void *root, void *arg __unused)
                 sched_timespecclear(&r->root_wait);                  sched_timespecclear(&r->root_wait);
   
         if (r->root_wait.tv_sec != -1 && r->root_wait.tv_nsec != -1) {          if (r->root_wait.tv_sec != -1 && r->root_wait.tv_nsec != -1) {
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
                 timeout = &r->root_wait;                  timeout = &r->root_wait;
   #elif SUP_ENABLE == EP_SUPPORT
                   timeout = r->root_wait.tv_sec * 1000 + r->root_wait.tv_nsec / 1000000;
 #else  #else
                 sched_timespec2val(&r->root_wait, &tv);                  sched_timespec2val(&r->root_wait, &tv);
                 timeout = &tv;                  timeout = &tv;
 #endif  /* KQ_SUPPORT */  #endif  /* KQ_SUPPORT */
         } else if (sched_timespecisinf(&r->root_poll))          } else if (sched_timespecisinf(&r->root_poll))
   #if SUP_ENABLE == EP_SUPPORT
                   timeout = -1;
   #else
                 timeout = NULL;                  timeout = NULL;
   #endif
         else {          else {
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
                 timeout = &r->root_poll;                  timeout = &r->root_poll;
   #elif SUP_ENABLE == EP_SUPPORT
                   timeout = r->root_poll.tv_sec * 1000 + r->root_poll.tv_nsec / 1000000;
 #else  #else
                 sched_timespec2val(&r->root_poll, &tv);                  sched_timespec2val(&r->root_poll, &tv);
                 timeout = &tv;                  timeout = &tv;
 #endif  /* KQ_SUPPORT */  #endif  /* KQ_SUPPORT */
         }          }
   
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         if ((en = kevent(r->root_kq, NULL, 0, res, KQ_EVENTS, timeout)) == -1) {          if ((en = kevent(r->root_kq, NULL, 0, res, KQ_EVENTS, timeout)) == -1) {
   #elif SUP_ENABLE == EP_SUPPORT
           if ((en = epoll_wait(r->root_kq, res, KQ_EVENTS, timeout)) == -1) {
 #else  #else
         rfd = xfd = r->root_fds[0];          rfd = xfd = r->root_fds[0];
         wfd = r->root_fds[1];          wfd = r->root_fds[1];
Line 770  sched_hook_fetch(void *root, void *arg __unused) Line 814  sched_hook_fetch(void *root, void *arg __unused)
         /* kevent dispatcher */          /* kevent dispatcher */
         now.tv_sec = now.tv_nsec = 0;          now.tv_sec = now.tv_nsec = 0;
         /* Go and catch the cat into pipes ... */          /* Go and catch the cat into pipes ... */
#if SUP_ENABLE == KQ_ENABLE#if SUP_ENABLE == KQ_SUPPORT
         for (i = 0; i < en; i++) {          for (i = 0; i < en; i++) {
                 memcpy(evt, &res[i], sizeof evt);                  memcpy(evt, &res[i], sizeof evt);
                 evt->flags = EV_DELETE;                  evt->flags = EV_DELETE;

Removed from v.1.27.2.3  
changed lines
  Added in v.1.27.2.5


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>