mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kent Overstreet <koverstreet@google.com>
To: linux-kernel@vger.kernel.org, linux-bcache@vger.kernel.org
Cc: Kent Overstreet <koverstreet@google.com>,
	tj@kernel.org, axboe@kernel.dk, paul.gortmaker@windriver.com
Subject: [PATCH 2/3] timerqueue: convert to generic rb tree code
Date: Fri, 25 May 2012 13:57:40 -0700	[thread overview]
Message-ID: <1337979461-19654-3-git-send-email-koverstreet@google.com> (raw)
In-Reply-To: <1337979461-19654-1-git-send-email-koverstreet@google.com>

Change-Id: Ib31c42c037203b7eb78515673475130db9fa6b0b

Signed-off-by: Kent Overstreet <koverstreet@google.com>
---
 lib/timerqueue.c |   23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/lib/timerqueue.c b/lib/timerqueue.c
index a382e4a..3014abe 100644
--- a/lib/timerqueue.c
+++ b/lib/timerqueue.c
@@ -27,6 +27,14 @@
 #include <linux/rbtree.h>
 #include <linux/export.h>
 
+static int timerqueue_cmp(struct rb_node *l, struct rb_node *r)
+{
+	return clamp_t(int64_t,
+		       rb_entry(l, struct timerqueue_node, node)->expires.tv64 -
+		       rb_entry(r, struct timerqueue_node, node)->expires.tv64,
+		       -1, 1);
+}
+
 /**
  * timerqueue_add - Adds timer to timerqueue.
  *
@@ -38,23 +46,10 @@
  */
 void timerqueue_add(struct timerqueue_head *head, struct timerqueue_node *node)
 {
-	struct rb_node **p = &head->head.rb_node;
-	struct rb_node *parent = NULL;
-	struct timerqueue_node  *ptr;
-
 	/* Make sure we don't add nodes that are already added */
 	WARN_ON_ONCE(!RB_EMPTY_NODE(&node->node));
 
-	while (*p) {
-		parent = *p;
-		ptr = rb_entry(parent, struct timerqueue_node, node);
-		if (node->expires.tv64 < ptr->expires.tv64)
-			p = &(*p)->rb_left;
-		else
-			p = &(*p)->rb_right;
-	}
-	rb_link_node(&node->node, parent, p);
-	rb_insert_color(&node->node, &head->head);
+	rb_insert_allow_dup(&head->head, &node->node, timerqueue_cmp);
 
 	if (!head->next || node->expires.tv64 < head->next->expires.tv64)
 		head->next = node;
-- 
1.7.9.3.327.g2980b


  parent reply	other threads:[~2012-05-25 20:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-25 20:57 [PATCH 0/3] Generic " Kent Overstreet
2012-05-25 20:57 ` [PATCH 1/3] rbtree: Add rb_insert(), rb_search(), etc Kent Overstreet
2012-05-28 23:35   ` Tejun Heo
2012-05-25 20:57 ` Kent Overstreet [this message]
2012-05-25 20:57 ` [PATCH 3/3] block: convert elevator to generic rb tree code Kent Overstreet
2012-05-28 23:17   ` Tejun Heo
2012-05-29  3:25     ` Kent Overstreet
2012-05-29  5:24       ` Tejun Heo
2012-05-29  6:57         ` Kent Overstreet
2012-05-28 23:22 ` [PATCH 0/3] Generic " Tejun Heo
2012-05-29  3:30   ` Kent Overstreet
2012-05-29  5:28     ` Tejun Heo
2012-05-31 21:03 ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1337979461-19654-3-git-send-email-koverstreet@google.com \
    --to=koverstreet@google.com \
    --cc=axboe@kernel.dk \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome