diff options
| author | Jafar Al-Gharaibeh <jafar@atcorp.com> | 2022-12-09 20:19:28 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-09 20:19:28 -0600 |
| commit | b7f08a6fbd03382082166e4fae27f35868a04601 (patch) | |
| tree | f550e8fb712f66c50a8bbccddd46d3212e26467f /lib/linklist.c | |
| parent | e3f5a669e486d5f1e416a8199586eb47ba3865e2 (diff) | |
| parent | cda0f501fb9a3b0dca429dac628ea4cc9566e233 (diff) | |
Merge pull request #12482 from donaldsharp/mem_this
Mem this
Diffstat (limited to 'lib/linklist.c')
| -rw-r--r-- | lib/linklist.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/linklist.c b/lib/linklist.c index d1b57084ef..d2a29b7ed1 100644 --- a/lib/linklist.c +++ b/lib/linklist.c @@ -28,6 +28,37 @@ DEFINE_MTYPE_STATIC(LIB, LINK_LIST, "Link List"); DEFINE_MTYPE_STATIC(LIB, LINK_NODE, "Link Node"); +/* these *do not* cleanup list nodes and referenced data, as the functions + * do - these macros simply {de,at}tach a listnode from/to a list. + */ + +/* List node attach macro. */ +#define LISTNODE_ATTACH(L, N) \ + do { \ + (N)->prev = (L)->tail; \ + (N)->next = NULL; \ + if ((L)->head == NULL) \ + (L)->head = (N); \ + else \ + (L)->tail->next = (N); \ + (L)->tail = (N); \ + (L)->count++; \ + } while (0) + +/* List node detach macro. */ +#define LISTNODE_DETACH(L, N) \ + do { \ + if ((N)->prev) \ + (N)->prev->next = (N)->next; \ + else \ + (L)->head = (N)->next; \ + if ((N)->next) \ + (N)->next->prev = (N)->prev; \ + else \ + (L)->tail = (N)->prev; \ + (L)->count--; \ + } while (0) + struct list *list_new(void) { return XCALLOC(MTYPE_LINK_LIST, sizeof(struct list)); |
