-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: John Sanpe <[email protected]>
- Loading branch information
Showing
4 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright(c) 2024 John Sanpe <[email protected]> | ||
*/ | ||
|
||
#include <xdbd_timer.h> | ||
|
||
BFDEV_RB_ROOT_CACHED(xdbd_timers); | ||
|
||
static inline long | ||
timer_cmp(const bfdev_rb_node_t *key1, const bfdev_rb_node_t *key2, void *pdata) | ||
{ | ||
xdbd_timer_t *node1, *node2; | ||
|
||
node1 = bfdev_container_of(key1, xdbd_timer_t, rb); | ||
node2 = bfdev_container_of(key2, xdbd_timer_t, rb); | ||
|
||
/* Ignoring conflicts */ | ||
return node1->time < node2->time ? BFDEV_LT : BFDEV_BT; | ||
} | ||
|
||
xdbd_timer_t * | ||
xdbd_first_timer(void) | ||
{ | ||
return bfdev_rb_cached_first_entry(&xdbd_timers, xdbd_timer_t, rb); | ||
} | ||
|
||
void | ||
xdbd_add_timer(xdbd_timer_t *timer) | ||
{ | ||
bfdev_rb_cached_insert(&xdbd_timers, &timer->rb, timer_cmp, NULL); | ||
} | ||
|
||
void | ||
xdbd_remove_timer(xdbd_timer_t *timer) | ||
{ | ||
bfdev_rb_cached_remove(&xdbd_timers, &timer->rb); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/* | ||
* Copyright(c) 2024 John Sanpe <[email protected]> | ||
*/ | ||
|
||
#ifndef __XDBD_TIMER__H__ | ||
#define __XDBD_TIMER__H__ | ||
|
||
#include <xdbd.h> | ||
#include <bfdev.h> | ||
|
||
struct xdbd_timer_s { | ||
bfdev_rb_node_t rb; | ||
xdbd_msec_t time; | ||
}; | ||
|
||
extern bfdev_rb_root_cached_t xdbd_timers; | ||
|
||
extern xdbd_timer_t * | ||
xdbd_first_timer(void); | ||
|
||
extern void | ||
xdbd_add_timer(xdbd_timer_t *timer); | ||
|
||
extern void | ||
xdbd_remove_timer(xdbd_timer_t *timer); | ||
|
||
#endif /* __XDBD_TIMER__H__ */ |