diff mbox

[PATCHv3,5/9] api: cpumask: add odp_cpumask_first

Message ID 1421275706-11176-6-git-send-email-anders.roxell@linaro.org
State Accepted
Commit b9c94bc29cd96898308f1a8f5273d69c70270e7f
Headers show

Commit Message

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

To get the first element in order to be able 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 |  7 +++++++
 platform/linux-generic/odp_cpumask.c             | 10 ++++++++++
 2 files changed, 17 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 0090f9a..cccbb62 100644
--- a/platform/linux-generic/include/api/odp_cpumask.h
+++ b/platform/linux-generic/include/api/odp_cpumask.h
@@ -132,6 +132,13 @@  int odp_cpumask_equal(const odp_cpumask_t *mask1,
 void odp_cpumask_copy(odp_cpumask_t *dest, const odp_cpumask_t *src);
 
 /**
+ * Find first bit set in mask
+ *
+ * @return cpu else -1 if no bits set in cpumask
+ */
+int odp_cpumask_first(const odp_cpumask_t *mask);
+
+/**
  * @}
  */
 
diff --git a/platform/linux-generic/odp_cpumask.c b/platform/linux-generic/odp_cpumask.c
index 6be7f1e..a3bb176 100644
--- a/platform/linux-generic/odp_cpumask.c
+++ b/platform/linux-generic/odp_cpumask.c
@@ -175,3 +175,13 @@  void odp_cpumask_copy(odp_cpumask_t *dest, const odp_cpumask_t *src)
 {
 	memcpy(&dest->set, &src->set, sizeof(src->set));
 }
+
+int odp_cpumask_first(const odp_cpumask_t *mask)
+{
+	int cpu;
+
+	for (cpu = 0; cpu < CPU_SETSIZE; cpu++)
+		if (odp_cpumask_isset(mask, cpu))
+			return cpu;
+	return -1;
+}