summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorPeter Lieven <pl@kamp.de>2014-10-27 10:18:43 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2014-11-03 09:48:41 +0000
commitac3a8726644d4783eacf54212d23db01d1d30044 (patch)
tree765e54ea8d8dd2358dccf344835843250f730307 /include
parent0a2923f8488498000eec54871456aa64a4391da4 (diff)
downloadqemu-ac3a8726644d4783eacf54212d23db01d1d30044.tar.gz
qemu-ac3a8726644d4783eacf54212d23db01d1d30044.tar.bz2
qemu-ac3a8726644d4783eacf54212d23db01d1d30044.zip
util: introduce MIN_NON_ZERO
at least in block layer we have the case of limits being defined for a BlockDriverState. However, in this context often zero (0) has the special meanining of undefined which means no limit. If two of those limits are combined and the minimum is needed the minimum function should only return zero if both parameters are zero. Signed-off-by: Peter Lieven <pl@kamp.de> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/qemu/osdep.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index 1565404f7e..c0324344d5 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -68,6 +68,12 @@ typedef signed int int_fast16_t;
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
+/* Minimum function that returns zero only iff both values are zero.
+ * Intended for use with unsigned values only. */
+#ifndef MIN_NON_ZERO
+#define MIN_NON_ZERO(a, b) (((a) != 0 && (a) < (b)) ? (a) : (b))
+#endif
+
#ifndef ROUND_UP
#define ROUND_UP(n,d) (((n) + (d) - 1) & -(d))
#endif