Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[sfrench/cifs-2.6.git] / lib / timerqueue.c
index bc7e64df27df67d75de09bc26fd6b1a5c6d82c6b..c5271096459306fb22f63699422fa4b7495783ab 100644 (file)
  */
 bool timerqueue_add(struct timerqueue_head *head, struct timerqueue_node *node)
 {
-       struct rb_node **p = &head->head.rb_node;
+       struct rb_node **p = &head->rb_root.rb_root.rb_node;
        struct rb_node *parent = NULL;
-       struct timerqueue_node  *ptr;
+       struct timerqueue_node *ptr;
+       bool leftmost = true;
 
        /* Make sure we don't add nodes that are already added */
        WARN_ON_ONCE(!RB_EMPTY_NODE(&node->node));
@@ -36,19 +37,17 @@ bool timerqueue_add(struct timerqueue_head *head, struct timerqueue_node *node)
        while (*p) {
                parent = *p;
                ptr = rb_entry(parent, struct timerqueue_node, node);
-               if (node->expires < ptr->expires)
+               if (node->expires < ptr->expires) {
                        p = &(*p)->rb_left;
-               else
+               } else {
                        p = &(*p)->rb_right;
+                       leftmost = false;
+               }
        }
        rb_link_node(&node->node, parent, p);
-       rb_insert_color(&node->node, &head->head);
+       rb_insert_color_cached(&node->node, &head->rb_root, leftmost);
 
-       if (!head->next || node->expires < head->next->expires) {
-               head->next = node;
-               return true;
-       }
-       return false;
+       return leftmost;
 }
 EXPORT_SYMBOL_GPL(timerqueue_add);
 
@@ -65,15 +64,10 @@ bool timerqueue_del(struct timerqueue_head *head, struct timerqueue_node *node)
 {
        WARN_ON_ONCE(RB_EMPTY_NODE(&node->node));
 
-       /* update next pointer */
-       if (head->next == node) {
-               struct rb_node *rbn = rb_next(&node->node);
-
-               head->next = rb_entry_safe(rbn, struct timerqueue_node, node);
-       }
-       rb_erase(&node->node, &head->head);
+       rb_erase_cached(&node->node, &head->rb_root);
        RB_CLEAR_NODE(&node->node);
-       return head->next != NULL;
+
+       return !RB_EMPTY_ROOT(&head->rb_root.rb_root);
 }
 EXPORT_SYMBOL_GPL(timerqueue_del);