Add a _move_head and _move_tail function to move a node
Also be more consisten in cometns about tailq instead of list
This commit is contained in:
+28
-9
@@ -21,7 +21,8 @@
|
|||||||
* Note that unlike the sys/queue.h TAILQ, the list does
|
* Note that unlike the sys/queue.h TAILQ, the list does
|
||||||
* not begin/end with a NULL pointer. For a entry node, the beginning/end
|
* not begin/end with a NULL pointer. For a entry node, the beginning/end
|
||||||
* is a back pointer to the head node.
|
* is a back pointer to the head node.
|
||||||
* Traditional linked list TailQ
|
*
|
||||||
|
* Traditional linked list TailQ
|
||||||
* node->prev == NULL node->prev == head
|
* node->prev == NULL node->prev == head
|
||||||
* node->next == NULL node->next == head
|
* node->next == NULL node->next == head
|
||||||
*
|
*
|
||||||
@@ -69,19 +70,19 @@ static UC_INLINE void uc_tailq_insert(struct TailQ *entry,
|
|||||||
next->prev = entry;
|
next->prev = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Insert entry to the tail(end) of the list
|
/** Insert entry to the tail(end) of the tailq
|
||||||
*/
|
*/
|
||||||
static UC_INLINE void uc_tailq_insert_tail(struct TailQ *head, struct TailQ *entry)
|
static UC_INLINE void uc_tailq_insert_tail(struct TailQ *head, struct TailQ *entry)
|
||||||
{
|
{
|
||||||
//head becomes entry->next, signalling the end of the list
|
//head becomes entry->next, signalling the end of the tailq
|
||||||
uc_tailq_insert(entry, head->prev, head);
|
uc_tailq_insert(entry, head->prev, head);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Insert entry to the head(start) of the list
|
/** Insert entry to the head(start) of the tailq
|
||||||
*/
|
*/
|
||||||
static UC_INLINE void uc_tailq_insert_head(struct TailQ *head, struct TailQ *entry)
|
static UC_INLINE void uc_tailq_insert_head(struct TailQ *head, struct TailQ *entry)
|
||||||
{
|
{
|
||||||
//head becomes entry->prev, signalling the end of the list
|
//head becomes entry->prev, signalling the end of the tailq
|
||||||
uc_tailq_insert(entry, head, head->next);
|
uc_tailq_insert(entry, head, head->next);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,8 +94,8 @@ static UC_INLINE void uc_tailq_link(struct TailQ *first, struct TailQ *second)
|
|||||||
second->prev = first;
|
second->prev = first;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove the entry from the list it is part of.
|
/** Remove the entry from the tailq it is part of.
|
||||||
* (It *must* already be part of a list.
|
* (It *must* already be part of a tailq.
|
||||||
*/
|
*/
|
||||||
static UC_INLINE void uc_tailq_remove(struct TailQ *entry)
|
static UC_INLINE void uc_tailq_remove(struct TailQ *entry)
|
||||||
{
|
{
|
||||||
@@ -105,7 +106,25 @@ static UC_INLINE void uc_tailq_remove(struct TailQ *entry)
|
|||||||
entry->prev = (void*)0x102;
|
entry->prev = (void*)0x102;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Iterate over a tailq. The list cannot be altered while iterating.
|
/** Move entry from its current tailq to the head of another tailq.
|
||||||
|
* (entry must be part of a tailq)
|
||||||
|
*/
|
||||||
|
static UC_INLINE void uc_tailq_move_head(struct TailQ *entry, struct TailQ *head)
|
||||||
|
{
|
||||||
|
uc_tailq_link(entry->prev, entry->next);
|
||||||
|
uc_taiq_insert(entry, head, head->next);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Move entry from its current tailq to the tail of another tailq.
|
||||||
|
* (entry must be part of a tailq)
|
||||||
|
*/
|
||||||
|
static UC_INLINE void uc_tailq_move_tail(struct TailQ *entry, struct TailQ *head)
|
||||||
|
{
|
||||||
|
uc_tailq_link(entry->prev, entry->next);
|
||||||
|
uc_taiq_insert(entry, head->prev, head);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Iterate over a tailq. The tailq cannot be altered while iterating.
|
||||||
*
|
*
|
||||||
* @param entry a struct TailQ* to which each element is assigned.
|
* @param entry a struct TailQ* to which each element is assigned.
|
||||||
* @param head the struct TailQ* head of the tailq
|
* @param head the struct TailQ* head of the tailq
|
||||||
@@ -113,7 +132,7 @@ static UC_INLINE void uc_tailq_remove(struct TailQ *entry)
|
|||||||
#define UC_TAILQ_FOREACH(entry, head)\
|
#define UC_TAILQ_FOREACH(entry, head)\
|
||||||
for ((entry) = (head)->next; (entry) != (head); (entry) = (entry)->next)
|
for ((entry) = (head)->next; (entry) != (head); (entry) = (entry)->next)
|
||||||
|
|
||||||
/** Iterate over a tailq in reverse order. The list cannot be altered while
|
/** Iterate over a tailq in reverse order. The tailq cannot be altered while
|
||||||
* iterating.
|
* iterating.
|
||||||
*
|
*
|
||||||
* @param entry a struct TailQ* to which each element is assigned.
|
* @param entry a struct TailQ* to which each element is assigned.
|
||||||
|
|||||||
Reference in New Issue
Block a user