]> xenbits.xensource.com Git - xen.git/commitdiff
tools/libxl: Introduce min and max macros
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 16 Mar 2015 13:29:49 +0000 (13:29 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 18 Mar 2015 11:31:57 +0000 (11:31 +0000)
This is the same set used by libxc.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
CC: Ian Campbell <Ian.Campbell@citrix.com>
CC: Ian Jackson <Ian.Jackson@eu.citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
tools/libxl/libxl_internal.h

index 934465a87bf8103eab37a627c6bfc9fa3a42051d..fcbec7f586fdfb5b9e883308cfdb4bc2b4bb959a 100644 (file)
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
+#define min(X, Y) ({                             \
+            const typeof (X) _x = (X);           \
+            const typeof (Y) _y = (Y);           \
+            (void) (&_x == &_y);                 \
+            (_x < _y) ? _x : _y; })
+#define max(X, Y) ({                             \
+            const typeof (X) _x = (X);           \
+            const typeof (Y) _y = (Y);           \
+            (void) (&_x == &_y);                 \
+            (_x > _y) ? _x : _y; })
+
+#define min_t(type, x, y)                                               \
+    ({ const type _x = (x); const type _y = (y); _x < _y ? _x: _y; })
+#define max_t(type, x, y)                                               \
+    ({ const type _x = (x); const type _y = (y); _x > _y ? _x: _y; })
+
 #define LIBXL__LOGGING_ENABLED
 
 #ifdef LIBXL__LOGGING_ENABLED