<p>dexter has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/24801">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">linuxlist: add functions to check entry presence and list end<br><br>The current linuxlist implementation has not convinient way to check if<br>a given element is actually contained in a list. However, this may be<br>helpful when we must be sure that a pointer to a list element is still<br>valid.<br><br>Also it is not very easy to check if an element is actually the last<br>element of a list. However this is needed when iterating the list from<br>osmo_select_main()<br><br>Change-Id: Icf455bf6ba9d60bd311af17c9e80febaa42cacc9<br>Related: SYS#4971<br>---<br>M include/osmocom/core/linuxlist.h<br>1 file changed, 25 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/01/24801/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/core/linuxlist.h b/include/osmocom/core/linuxlist.h</span><br><span>index f28f88b..6b50ae0 100644</span><br><span>--- a/include/osmocom/core/linuxlist.h</span><br><span>+++ b/include/osmocom/core/linuxlist.h</span><br><span>@@ -394,7 +394,32 @@</span><br><span>        return i;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Check whether a given element actually exists in the list.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param head the llist head of the list to check.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param entry the element to check.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \returns true if the element exists in the list, false otherwise.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static inline bool llist_contains(struct llist_head *head, struct llist_head *entry)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct llist_head *llist_entry;</span><br><span style="color: hsl(120, 100%, 40%);">+       llist_for_each(llist_entry, head) {</span><br><span style="color: hsl(120, 100%, 40%);">+           if (llist_entry == entry)</span><br><span style="color: hsl(120, 100%, 40%);">+                     return true;</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+     return false;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! Check whether a given element is the last element of the list.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param head the llist head of the list to check.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \param entry the element to check.</span><br><span style="color: hsl(120, 100%, 40%);">+ *  \returns true if the element is the last element, false otherwise.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static inline bool llist_is_last(struct llist_head *head, struct llist_head *entry)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+   if (entry == head->prev)</span><br><span style="color: hsl(120, 100%, 40%);">+           return true;</span><br><span style="color: hsl(120, 100%, 40%);">+  return false;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span> </span><br><span> /*! Double linked lists with a single pointer list head.</span><br><span>  * Mostly useful for hash tables where the two pointer list head is</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/24801">change 24801</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/24801"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: Icf455bf6ba9d60bd311af17c9e80febaa42cacc9 </div>
<div style="display:none"> Gerrit-Change-Number: 24801 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>