hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/lib/timerqueue.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Generic Timer-queue
34 *
....@@ -6,20 +7,6 @@
67 *
78 * NOTE: All of the following functions need to be serialized
89 * to avoid races. No locking is done by this library code.
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with this program; if not, write to the Free Software
22
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2310 */
2411
2512 #include <linux/bug.h>
....@@ -39,9 +26,10 @@
3926 */
4027 bool timerqueue_add(struct timerqueue_head *head, struct timerqueue_node *node)
4128 {
42
- struct rb_node **p = &head->head.rb_node;
29
+ struct rb_node **p = &head->rb_root.rb_root.rb_node;
4330 struct rb_node *parent = NULL;
44
- struct timerqueue_node *ptr;
31
+ struct timerqueue_node *ptr;
32
+ bool leftmost = true;
4533
4634 /* Make sure we don't add nodes that are already added */
4735 WARN_ON_ONCE(!RB_EMPTY_NODE(&node->node));
....@@ -49,19 +37,17 @@
4937 while (*p) {
5038 parent = *p;
5139 ptr = rb_entry(parent, struct timerqueue_node, node);
52
- if (node->expires < ptr->expires)
40
+ if (node->expires < ptr->expires) {
5341 p = &(*p)->rb_left;
54
- else
42
+ } else {
5543 p = &(*p)->rb_right;
44
+ leftmost = false;
45
+ }
5646 }
5747 rb_link_node(&node->node, parent, p);
58
- rb_insert_color(&node->node, &head->head);
48
+ rb_insert_color_cached(&node->node, &head->rb_root, leftmost);
5949
60
- if (!head->next || node->expires < head->next->expires) {
61
- head->next = node;
62
- return true;
63
- }
64
- return false;
50
+ return leftmost;
6551 }
6652 EXPORT_SYMBOL_GPL(timerqueue_add);
6753
....@@ -78,15 +64,10 @@
7864 {
7965 WARN_ON_ONCE(RB_EMPTY_NODE(&node->node));
8066
81
- /* update next pointer */
82
- if (head->next == node) {
83
- struct rb_node *rbn = rb_next(&node->node);
84
-
85
- head->next = rb_entry_safe(rbn, struct timerqueue_node, node);
86
- }
87
- rb_erase(&node->node, &head->head);
67
+ rb_erase_cached(&node->node, &head->rb_root);
8868 RB_CLEAR_NODE(&node->node);
89
- return head->next != NULL;
69
+
70
+ return !RB_EMPTY_ROOT(&head->rb_root.rb_root);
9071 }
9172 EXPORT_SYMBOL_GPL(timerqueue_del);
9273