Reputation: 5413
I have find a lot of references to INIT_LIST_HEAD
but I couldn't find anything on INIT_LIST_HEAD_FIRST
. what's the differences between the two.
INIT_LIST_HEAD(&orig_event->list);
INIT_LIST_HEAD_FIRST(orig_event->event_list);
INIT_LIST_HEAD_FIRST(orig_event->rt_hist_list);
one pass in the address of thing pointed by a pointer and another pass in just something pointed by a pointer.
INIT_HLIST_HEAD(&bat_priv->gw.list);
INIT_LIST_HEAD(&bat_priv->tt.changes_list);
Also what are differences between INIT_LIST_HEAD
and INIT_HLIST_HEAD
?
Upvotes: 0
Views: 505
Reputation: 493
Here are the definitions for each macro, from list-batman.h
:
00062 #define INIT_LIST_HEAD(ptr) do { \
00063 (ptr)->next = (ptr); \
00064 } while (0)
00065
00066 #define INIT_LIST_HEAD_FIRST(ptr) \
00067 ptr.next = (struct list_head *)&ptr; ptr.prev = (struct list_head *)&ptr; \
00068
(Line 68 is blank, so the continuation from line 67 doesn't do anything.)
So, what does it mean? This question explains the peculiar do {
. . . } while (0)
construction:
Why use apparently meaningless do-while and if-else statements in macros?
Thus, INIT_LIST_HEAD(ptr)
is meant to step forward to the next list element.
The INIT_LIST_HEAD_FIRST(ptr)
sets the next and previous pointers of a list_head
structure, which is the empty state of a doubly linked list.
I'm puzzled about the names of the macros, because both sound like initializations, but that's a question for the developers who wrote the code.
More:
I initially overlooked the question about INIT_HLIST_HEAD
. I looked it up, and linux/list.h
defines it as this:
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
It deals with the hlist_node
structure, which contains a next
pointer and a pprev
pointer to pointer. The macro initializes the list.
Upvotes: 1