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/.
Neels Hofmeyr gerrit-no-reply at lists.osmocom.orgNeels Hofmeyr has submitted this change and it was merged. Change subject: linuxlist.h: add llist_count() ...................................................................... linuxlist.h: add llist_count() After subchan_demux.c in libosmo-abis, osmo-bts/common/vty.c and openbsc's gtphub_test.c, more places would like to count the llist items (mostly unit tests). Instead of proliferating numerous local implementations, add here. NOTE: other than the previous llist_len() implementations, this one returns an *unsigned* length, which might need some adjusting of current callers. Call this llist_count() rather than llist_len() to highlight the fact that this is actively iterating. This also avoids a potential naming conflict when library versions mismatch. Change-Id: Ic49adc7a346f5722bf624d7d3b4a735e4220ae15 --- M include/osmocom/core/linuxlist.h 1 file changed, 16 insertions(+), 0 deletions(-) Approvals: Jenkins Builder: Verified Holger Freyther: Looks good to me, approved diff --git a/include/osmocom/core/linuxlist.h b/include/osmocom/core/linuxlist.h index 1c83395..affa827 100644 --- a/include/osmocom/core/linuxlist.h +++ b/include/osmocom/core/linuxlist.h @@ -351,6 +351,22 @@ for ((pos) = (pos)->next, prefetch((pos)->next); (pos) != (head); \ (pos) = (pos)->next, ({ smp_read_barrier_depends(); 0;}), prefetch((pos)->next)) +/*! \brief count nr of llist items by iterating. + * \param head The llist head to count items of. + * \returns Number of items. + * + * This function is not efficient, mostly useful for small lists and non time + * critical cases like unit tests. + */ +static inline unsigned int llist_count(struct llist_head *head) +{ + struct llist_head *entry; + unsigned int i = 0; + llist_for_each(entry, head) + i++; + return i; +} + /*! * }@ */ -- To view, visit https://gerrit.osmocom.org/1563 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic49adc7a346f5722bf624d7d3b4a735e4220ae15 Gerrit-PatchSet: 5 Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de> Gerrit-Reviewer: Holger Freyther <holger at freyther.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: Max <msuraev at sysmocom.de> Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>