Parcourir la source

sq: Add sq_iter_next function

Function for traverse thru all active sq items.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Lucas Zampieri <lcasmz54@gmail.com>
Jan Friesse il y a 7 ans
Parent
commit
8850e226af
1 fichiers modifiés avec 23 ajouts et 0 suppressions
  1. 23 0
      include/corosync/sq.h

+ 23 - 0
include/corosync/sq.h

@@ -401,4 +401,27 @@ static inline void sq_items_release (struct sq *sq, unsigned int seqid)
 	sq->head_seqid = seqid + 1;
 }
 
+/*
+ * Iter thru all active items. pos should be initialized to 0 before
+ * first call of this function.
+ */
+static inline void *sq_iter_next(const struct sq *sq, unsigned int *pos)
+{
+	char *sq_item;
+
+	for (; *pos < sq->item_count; (*pos)++) {
+		if (sq->items_inuse[*pos] != 0) {
+			sq_item = (char *)sq->items + ((*pos) * sq->size_per_item);
+			/*
+			 * Move to next item so next call doesn't continue on same item
+			 */
+			(*pos)++;
+
+			return (sq_item);
+		}
+	}
+
+	return (NULL);
+}
+
 #endif /* SORTQUEUE_H_DEFINED */