list: add list_replace

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-04-14 18:29:45 +01:00
parent adc52798db
commit 27603343a1
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 7 additions and 0 deletions

View File

@ -66,6 +66,13 @@ static inline void list_init_head(struct list_node *head) {
head->next = head->prev = head; head->next = head->prev = head;
} }
/// Replace list node `old` with `n`
static inline void list_replace(struct list_node *old, struct list_node *n) {
__list_insert_between(old->prev, old->next, n);
old->prev = (void *)-1;
old->next = (void *)-2;
}
/// Return true if head is the only node in the list. Under usual circumstances this means /// Return true if head is the only node in the list. Under usual circumstances this means
/// the list is empty /// the list is empty
static inline bool list_is_empty(const struct list_node *head) { static inline bool list_is_empty(const struct list_node *head) {