Skip to content

Commit

Permalink
dlist: Add functions to pop or free dlist head/tail
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Jun 26, 2020
1 parent c014543 commit 453ed12
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/lib/util/dlist.h
Expand Up @@ -392,6 +392,30 @@ static inline CC_HINT(nonnull(1)) void *fr_dlist_remove(fr_dlist_head_t *list_he
return (void *) (((uint8_t *) prev) - list_head->offset);
}

/** Remove the head item in a list
*
* @param[in] list_head to remove head item from.
* @return
* - The item removed.
* - NULL if not items in dlist.
*/
static inline CC_HINT(nonnull(1)) void *fr_dlist_pop_head(fr_dlist_head_t *list_head)
{
return fr_dlist_remove(list_head, fr_dlist_head(list_head));
}

/** Remove the tail item in a list
*
* @param[in] list_head to remove tail item from.
* @return
* - The item removed.
* - NULL if not items in dlist.
*/
static inline CC_HINT(nonnull(1)) void *fr_dlist_pop_tail(fr_dlist_head_t *list_head)
{
return fr_dlist_remove(list_head, fr_dlist_tail(list_head));
}

/** Check all items in the list are valid
*
* Checks item talloc headers and types to ensure they're consistent
Expand Down Expand Up @@ -451,6 +475,24 @@ static inline CC_HINT(nonnull) void fr_dlist_move(fr_dlist_head_t *list_dst, fr_
list_src->num_elements = 0;
}

/** Free the first item in the list
*
* @param[in] list_head to free head item in.
*/
static inline void fr_dlist_talloc_free_head(fr_dlist_head_t *list_head)
{
talloc_free(fr_dlist_pop_head(list_head));
}

/** Free the last item in the list
*
* @param[in] list_head to free tail item in.
*/
static inline void fr_dlist_talloc_free_tail(fr_dlist_head_t *list_head)
{
talloc_free(fr_dlist_pop_head(list_head));
}

/** Free all items in a doubly linked list (with talloc)
*
* @param[in] head of list to free.
Expand Down

0 comments on commit 453ed12

Please sign in to comment.