Change in libosmocore[master]: linuxlist: add functions to check entry presence and list end

dexter gerrit-no-reply at lists.osmocom.org
Tue Jun 29 14:11:29 UTC 2021


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/24801 )


Change subject: linuxlist: add functions to check entry presence and list end
......................................................................

linuxlist: add functions to check entry presence and list end

The current linuxlist implementation has not convinient way to check if
a given element is actually contained in a list. However, this may be
helpful when we must be sure that a pointer to a list element is still
valid.

Also it is not very easy to check if an element is actually the last
element of a list. However this is needed when iterating the list from
osmo_select_main()

Change-Id: Icf455bf6ba9d60bd311af17c9e80febaa42cacc9
Related: SYS#4971
---
M include/osmocom/core/linuxlist.h
1 file changed, 25 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/01/24801/1

diff --git a/include/osmocom/core/linuxlist.h b/include/osmocom/core/linuxlist.h
index f28f88b..6b50ae0 100644
--- a/include/osmocom/core/linuxlist.h
+++ b/include/osmocom/core/linuxlist.h
@@ -394,7 +394,32 @@
 	return i;
 }
 
+/*! Check whether a given element actually exists in the list.
+ *  \param head the llist head of the list to check.
+ *  \param entry the element to check.
+ *  \returns true if the element exists in the list, false otherwise.
+ */
+static inline bool llist_contains(struct llist_head *head, struct llist_head *entry)
+{
+	struct llist_head *llist_entry;
+	llist_for_each(llist_entry, head) {
+		if (llist_entry == entry)
+			return true;
+	}
+	return false;
+}
 
+/*! Check whether a given element is the last element of the list.
+ *  \param head the llist head of the list to check.
+ *  \param entry the element to check.
+ *  \returns true if the element is the last element, false otherwise.
+ */
+static inline bool llist_is_last(struct llist_head *head, struct llist_head *entry)
+{
+	if (entry == head->prev)
+		return true;
+	return false;
+}
 
 /*! Double linked lists with a single pointer list head.
  * Mostly useful for hash tables where the two pointer list head is

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24801
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Icf455bf6ba9d60bd311af17c9e80febaa42cacc9
Gerrit-Change-Number: 24801
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210629/01a2ffa9/attachment.htm>


More information about the gerrit-log mailing list