GNU Radio's TEST Package
llist.h
Go to the documentation of this file.
1
/*
2
* llist.h
3
*
4
* Simple double-linked list. Interface similar to the linux kernel
5
* one, but heavily simplified and rewritten to compile on other compilers
6
* than GCC.
7
*
8
* Copyright (C) 2013-2021 Sylvain Munaut
9
* SPDX-License-Identifier: GPL-3.0-or-later
10
*/
11
12
#pragma once
13
14
/*! \defgroup llist
15
* @{
16
*/
17
18
/*! \file llist.h
19
* \brief Simple double-linked list
20
*/
21
22
#include <stddef.h>
23
24
25
struct
llist_head
{
26
struct
llist_head
*
next
, *
prev
;
27
};
28
29
#define LLIST_HEAD_INIT(name) { &(name), &(name) }
30
31
#define LLIST_HEAD(name) \
32
struct llist_head name = LLIST_HEAD_INIT(name)
33
34
/**
35
* \brief Add a new entry after the specified head
36
* \param[in] new new entry to be added
37
* \param[in] head llist head to add it after
38
*/
39
static
inline
void
llist_add
(
struct
llist_head
*_new,
struct
llist_head
*head)
40
{
41
head->
next
->
prev
= _new;
42
_new->
next
= head->
next
;
43
_new->
prev
= head;
44
head->
next
= _new;
45
}
46
47
/**
48
* \brief Deletes entry from llist
49
* \param[in] entry the element to delete from the llist
50
*/
51
static
inline
void
llist_del
(
struct
llist_head
*entry)
52
{
53
entry->
next
->
prev
= entry->
prev
;
54
entry->
prev
->
next
= entry->
next
;
55
entry->
next
= (
struct
llist_head
*)0;
56
entry->
prev
= (
struct
llist_head
*)0;
57
}
58
59
/**
60
* \brief Get the struct for this entry
61
* \param[in] ptr the &struct llist_head pointer
62
* \param[in] type the type of the struct this is embedded in
63
* \param[in] member the name of the llist_struct within the struct
64
* \returns The struct for this entry
65
*/
66
#define llist_entry(ptr, type, member) \
67
((type *)( (char *)(ptr) - offsetof(type, member) ))
68
69
/**
70
* \brief Iterate over llist of given type
71
* \param[in] type the type of the loop counter
72
* \param[out] pos the type * to use as a loop counter
73
* \param[in] head the head for your llist
74
* \param[in] member the name of the llist_struct within the struct
75
*/
76
#define llist_for_each_entry(type, pos, head, member) \
77
for (pos = llist_entry((head)->next, type, member); \
78
&pos->member != (head); \
79
pos = llist_entry(pos->member.next, type, member))
80
81
/*! @} */
llist_add
static void llist_add(struct llist_head *_new, struct llist_head *head)
Add a new entry after the specified head.
Definition
llist.h:39
llist_del
static void llist_del(struct llist_head *entry)
Deletes entry from llist.
Definition
llist.h:51
llist_head
Definition
llist.h:25
llist_head::next
struct llist_head * next
Definition
llist.h:26
llist_head::prev
struct llist_head * prev
Definition
llist.h:26
lib
fosphor
llist.h
Generated by
1.9.8