Mistake on this page?
Report an issue in GitHub or email us
tfm_list.h
1 /*
2  * Copyright (c) 2018, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 #ifndef __TFM_LIST_H__
8 #define __TFM_LIST_H__
9 
10 /* List structure */
12  struct tfm_list_node_t *prev;
13  struct tfm_list_node_t *next;
14 };
15 
16 /**
17  * \brief Initialize list head.
18  *
19  * \param[in] head List head need to be initialized.
20  */
21 __STATIC_INLINE void tfm_list_init(struct tfm_list_node_t *head)
22 {
23  head->next = head;
24  head->prev = head;
25 }
26 
27 /**
28  * \brief Add one node to list tail.
29  *
30  * \param[in] head List head initialized by \ref tfm_list_init.
31  * \param[in] node List node want to be added.
32  */
33 __STATIC_INLINE void
34 tfm_list_add_tail(struct tfm_list_node_t *head, struct tfm_list_node_t *node)
35 {
36  head->prev->next = node;
37  node->prev = head->prev;
38  head->prev = node;
39  node->next = head;
40 }
41 
42 /**
43  * \brief Check if a list is empty.
44  *
45  * \param[in] head List head initialized by \ref tfm_list_init.
46  *
47  * \returns returns 1 for empty, or 0 for not.
48  */
49 __STATIC_INLINE int32_t tfm_list_is_empty(struct tfm_list_node_t *head)
50 {
51  return (head->next == head);
52 }
53 
54 /**
55  * \brief Insert one node to list head.
56  *
57  * \param[in] head List head initialized by \ref tfm_list_init.
58  * \param[in] node List node want to be inserted.
59  */
60 __STATIC_INLINE void
61 tfm_list_insert_first(struct tfm_list_node_t *head,
62  struct tfm_list_node_t *node)
63 {
64  node->next = head->next;
65  node->prev = head;
66  head->next->prev = node;
67  head->next = node;
68 }
69 
70 /**
71  * \brief Retrieve the fist node from list.
72  *
73  * \param[in] head List head initialized by \ref tfm_list_init.
74  *
75  * \returns Returns the pointer to first list node.
76  */
77 __STATIC_INLINE
78 struct tfm_list_node_t *tfm_list_first_node(struct tfm_list_node_t *head)
79 {
80  return head->next;
81 }
82 
83 /**
84  * \brief Delete one node from list.
85  *
86  * \param[in] node List node want to be deleted.
87  */
88 __STATIC_INLINE void tfm_list_del_node(struct tfm_list_node_t *node)
89 {
90  node->prev->next = node->next;
91  node->next->prev = node->prev;
92 }
93 
94 /* Go through each node of a list */
95 #define TFM_LIST_FOR_EACH(node, head) \
96  for (node = (head)->next; node != head; node = node->next)
97 
98 #endif
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.