diff mbox

[PATCHv3,7/9] api: cpumask: add odp_cpumask_next

Message ID 1421275706-11176-8-git-send-email-anders.roxell@linaro.org
State Accepted
Commit 7af97975609758b93db24bcdbf5342a310c60335
Headers show

Commit Message

Anders Roxell Jan. 14, 2015, 10:48 p.m. UTC
From: Robbie King <robking@cisco.com>

Finding the next element to traverse a mask.

Signed-off-by: Robbie King <robking@cisco.com>
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 platform/linux-generic/include/api/odp_cpumask.h | 21 +++++++++++++++++++++
 platform/linux-generic/odp_cpumask.c             |  8 ++++++++
 2 files changed, 29 insertions(+)
diff mbox

Patch

diff --git a/platform/linux-generic/include/api/odp_cpumask.h b/platform/linux-generic/include/api/odp_cpumask.h
index a81bca7..ebff9b0 100644
--- a/platform/linux-generic/include/api/odp_cpumask.h
+++ b/platform/linux-generic/include/api/odp_cpumask.h
@@ -146,6 +146,27 @@  int odp_cpumask_first(const odp_cpumask_t *mask);
 int odp_cpumask_last(const odp_cpumask_t *mask);
 
 /**
+ * Find next cpu in mask
+ *
+ * Finds the next cpu in the CPU mask, starting at the cpu passed.
+ * Use with odp_cpumask_first to traverse a CPU mask, i.e.
+ *
+ * int cpu = odp_cpumask_first(&mask);
+ * while (0 <= cpu) {
+ *     ...
+ *     ...
+ *     cpu = odp_cpumask_next(&mask, cpu);
+ * }
+ *
+ * @param mask        CPU mask to find next cpu in
+ * @param cpu         CPU to start from
+ * @return cpu found else -1
+ *
+ * @see odp_cpumask_first()
+ */
+int odp_cpumask_next(const odp_cpumask_t *mask, int cpu);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c
index 3930264..d9931b4 100644
--- a/platform/linux-generic/odp_cpumask.c
+++ b/platform/linux-generic/odp_cpumask.c
@@ -185,3 +185,11 @@  int odp_cpumask_last(const odp_cpumask_t *mask)
 			return cpu;
 	return -1;
 }
+
+int odp_cpumask_next(const odp_cpumask_t *mask, int cpu)
+{
+	for (cpu += 1; cpu < CPU_SETSIZE; cpu++)
+		if (odp_cpumask_isset(mask, cpu))
+			return cpu;
+	return -1;
+}