This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Harald Welte gerrit-no-reply at lists.osmocom.orgHarald Welte has submitted this change and it was merged. Change subject: linuxlist.h: add llist_first/last_entry macros ...................................................................... linuxlist.h: add llist_first/last_entry macros Copy list_first_entry, list_first_entry_or_null and list_last_entry from current linux kernel's tools/include/linux/list.h and rename to llist_*. Slightly adjust API doc but stay as close to the source as possible. This can replace similar implementations in osmo-bts-octphy's l1_if.c, in openbsc's gtphub.c and in osmo-hlr's gsup_server.c. Change-Id: I4eac5be0c0b2cede04464c4c3a0873102d952453 --- M include/osmocom/core/linuxlist.h 1 file changed, 30 insertions(+), 0 deletions(-) Approvals: Harald Welte: Looks good to me, approved Jenkins Builder: Verified diff --git a/include/osmocom/core/linuxlist.h b/include/osmocom/core/linuxlist.h index affa827..7d85077 100644 --- a/include/osmocom/core/linuxlist.h +++ b/include/osmocom/core/linuxlist.h @@ -215,6 +215,36 @@ #define llist_entry(ptr, type, member) \ container_of(ptr, type, member) +/*! \brief Get the first element from a list + * \param ptr the list head to take the element from. + * \param type the type of the struct this is embedded in. + * \param member the name of the list_head within the struct. + * + * Note, that list is expected to be not empty. + */ +#define llist_first_entry(ptr, type, member) \ + llist_entry((ptr)->next, type, member) + +/*! \brief Get the last element from a list + * \param ptr the list head to take the element from. + * \param type the type of the struct this is embedded in. + * \param member the name of the llist_head within the struct. + * + * Note, that list is expected to be not empty. + */ +#define llist_last_entry(ptr, type, member) \ + llist_entry((ptr)->prev, type, member) + +/*! \brief Get the first element from a list, or NULL + * \param ptr the list head to take the element from. + * \param type the type of the struct this is embedded in. + * \param member the name of the list_head within the struct. + * + * Note that if the list is empty, it returns NULL. + */ +#define llist_first_entry_or_null(ptr, type, member) \ + (!llist_empty(ptr) ? llist_first_entry(ptr, type, member) : NULL) + /*! \brief Iterate over a linked list * \param pos The \ref llist_head to use as a loop counter * \param head The head of the list over which to iterate -- To view, visit https://gerrit.osmocom.org/2076 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4eac5be0c0b2cede04464c4c3a0873102d952453 Gerrit-PatchSet: 2 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de> Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org> Gerrit-Reviewer: Jenkins Builder