Print this page
4823 don't open-code NSEC2MSEC and MSEC2NSEC


  78  *   input: iu_tq_t *: the timer queue
  79  *          iu_timer_node_t *: the timer node to insert into the list
  80  *          uint64_t: the number of milliseconds before this timer fires
  81  *  output: void
  82  */
  83 
  84 static void
  85 insert_timer(iu_tq_t *tq, iu_timer_node_t *node, uint64_t msec)
  86 {
  87         iu_timer_node_t *after = NULL;
  88 
  89         /*
  90          * find the node to insert this new node "after".  we do this
  91          * instead of the more intuitive "insert before" because with
  92          * the insert before approach, a null `before' node pointer
  93          * is overloaded in meaning (it could be null because there
  94          * are no items in the list, or it could be null because this
  95          * is the last item on the list, which are very different cases).
  96          */
  97 
  98         node->iutn_abs_timeout = gethrtime() + (msec * (NANOSEC / MILLISEC));
  99 
 100         if (tq->iutq_head != NULL &&
 101             tq->iutq_head->iutn_abs_timeout < node->iutn_abs_timeout)
 102                 for (after = tq->iutq_head; after->iutn_next != NULL;
 103                     after = after->iutn_next)
 104                         if (after->iutn_next->iutn_abs_timeout >
 105                             node->iutn_abs_timeout)
 106                                 break;
 107 
 108         node->iutn_next = after ? after->iutn_next : tq->iutq_head;
 109         node->iutn_prev = after;
 110         if (after == NULL)
 111                 tq->iutq_head = node;
 112         else
 113                 after->iutn_next = node;
 114 
 115         if (node->iutn_next != NULL)
 116                 node->iutn_next->iutn_prev = node;
 117 }
 118 




  78  *   input: iu_tq_t *: the timer queue
  79  *          iu_timer_node_t *: the timer node to insert into the list
  80  *          uint64_t: the number of milliseconds before this timer fires
  81  *  output: void
  82  */
  83 
  84 static void
  85 insert_timer(iu_tq_t *tq, iu_timer_node_t *node, uint64_t msec)
  86 {
  87         iu_timer_node_t *after = NULL;
  88 
  89         /*
  90          * find the node to insert this new node "after".  we do this
  91          * instead of the more intuitive "insert before" because with
  92          * the insert before approach, a null `before' node pointer
  93          * is overloaded in meaning (it could be null because there
  94          * are no items in the list, or it could be null because this
  95          * is the last item on the list, which are very different cases).
  96          */
  97 
  98         node->iutn_abs_timeout = gethrtime() + MSEC2NSEC(msec);
  99 
 100         if (tq->iutq_head != NULL &&
 101             tq->iutq_head->iutn_abs_timeout < node->iutn_abs_timeout)
 102                 for (after = tq->iutq_head; after->iutn_next != NULL;
 103                     after = after->iutn_next)
 104                         if (after->iutn_next->iutn_abs_timeout >
 105                             node->iutn_abs_timeout)
 106                                 break;
 107 
 108         node->iutn_next = after ? after->iutn_next : tq->iutq_head;
 109         node->iutn_prev = after;
 110         if (after == NULL)
 111                 tq->iutq_head = node;
 112         else
 113                 after->iutn_next = node;
 114 
 115         if (node->iutn_next != NULL)
 116                 node->iutn_next->iutn_prev = node;
 117 }
 118