From: Stephen Hemminger <[email protected]>

Add RTE_MIN3() to handle case of RTE_MIN(RTE_MIN(...)), and similarly
add RTE_MAX3(). Change name of local temporary variables in RTE_MAX()
to allow for combinations of RTE_MIN(RTE_MAX(...)) without causing
shadow declaration warnings.

Signed-off-by: Stephen Hemminger <[email protected]>
Signed-off-by: Bruce Richardson <[email protected]>
---
 lib/eal/include/rte_common.h | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h
index 9e7d84f929..36400e8e43 100644
--- a/lib/eal/include/rte_common.h
+++ b/lib/eal/include/rte_common.h
@@ -799,6 +799,19 @@ __extension__ typedef uint64_t RTE_MARKER64[0];
                _a < _b ? _a : _b; \
        })
 
+/**
+ * Macro to return the minimum of three numbers
+ */
+#define RTE_MIN3(a, b, c)                      \
+       __extension__ ({                        \
+               typeof (a) _a = (a);            \
+               typeof (b) _b = (b);            \
+               typeof (c) _c = (c);            \
+               _a < _b ? (_a < _c ? _a : _c)   \
+                       : (_b < _c ? _b : _c);  \
+       })
+
+
 /**
  * Macro to return the minimum of two numbers
  *
@@ -814,9 +827,21 @@ __extension__ typedef uint64_t RTE_MARKER64[0];
  */
 #define RTE_MAX(a, b) \
        __extension__ ({ \
-               typeof (a) _a = (a); \
-               typeof (b) _b = (b); \
-               _a > _b ? _a : _b; \
+               typeof (a) _ax = (a); \
+               typeof (b) _bx = (b); \
+               _ax > _bx ? _ax : _bx; \
+       })
+
+/**
+ * Macro to return the maximum of three numbers
+ */
+#define RTE_MAX3(a, b, c)                      \
+       __extension__ ({                        \
+               typeof (a) _a = (a);            \
+               typeof (b) _b = (b);            \
+               typeof (c) _c = (c);            \
+               _a > _b ? (_a > _c ? _a : _c)   \
+                       : (_b > _c ? _b : _c);  \
        })
 
 /**
-- 
2.48.1

Reply via email to