]> xenbits.xensource.com Git - people/jgross/xen.git/commitdiff
tools: define ROUNDUP() in tools/include/xen-tools/libs.h
authorJuergen Gross <jgross@suse.com>
Sun, 23 Aug 2020 08:00:11 +0000 (10:00 +0200)
committerJuergen Gross <jgross@suse.com>
Sun, 23 Aug 2020 08:48:30 +0000 (10:48 +0200)
Today there are multiple copies of the ROUNDUP() macro in various
sources and headers. Define it once in tools/include/xen-tools/libs.h.

Using xen-tools/libs.h enables removing copies of MIN() and MAX(), too.

Signed-off-by: Juergen Gross <jgross@suse.com>
tools/console/daemon/io.c
tools/include/xen-tools/libs.h
tools/libs/call/buffer.c
tools/libs/foreignmemory/linux.c
tools/libs/gnttab/private.h
tools/libxc/xg_private.h
tools/libxl/libxl_internal.h
tools/xenstore/xenstored_core.c

index a43c57edad62b371d9a2aa8adaf2c7af64beb28f..4af27ffc5d02c86e92de74b11b136db00fee71ab 100644 (file)
@@ -49,9 +49,7 @@
 #include <sys/ioctl.h>
 #include <libutil.h>
 #endif
-
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#include <xen-tools/libs.h>
 
 /* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */
 #define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2)
@@ -80,8 +78,6 @@ static struct pollfd  *fds;
 static unsigned int current_array_size;
 static unsigned int nr_fds;
 
-#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-
 struct buffer {
        char *data;
        size_t consumed;
index cc7dfc8c64530166aba5fd9b858fe562716f4a5c..a16e0c38070967fd2e3e4189b84efb639151cd4d 100644 (file)
@@ -59,4 +59,8 @@
     })
 #endif
 
+#ifndef ROUNDUP
+#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
+#endif
+
 #endif /* __XEN_TOOLS_LIBS__ */
index 0b6af2db603f743af3ac4c8036dc616dd1eac6e9..085674d882ae5d031460f26451f48a3da790e549 100644 (file)
 #include <errno.h>
 #include <string.h>
 #include <pthread.h>
+#include <xen-tools/libs.h>
 
 #include "private.h"
 
 #define DBGPRINTF(_m...) \
     xtl_log(xcall->logger, XTL_DEBUG, -1, "xencall:buffer", _m)
 
-#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-
 pthread_mutex_t cache_mutex = PTHREAD_MUTEX_INITIALIZER;
 
 static void cache_lock(xencall_handle *xcall)
index 8daa5828e3da2f1d0dee158ff91e8ba2274a4625..fe73d5ab72cc4c00ec7ec4fcae1fb1952df2daa4 100644 (file)
 
 #include <sys/mman.h>
 #include <sys/ioctl.h>
+#include <xen-tools/libs.h>
 
 #include "private.h"
 
-#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-
 #ifndef O_CLOEXEC
 #define O_CLOEXEC 0
 #endif
index c5e23639b141a86a5957d01d9dd930f695618ef3..eb6a6abe5419d4d952d4a55ea84305cffedc4bce 100644 (file)
@@ -5,9 +5,6 @@
 #include <xentoolcore_internal.h>
 #include <xengnttab.h>
 
-/* Set of macros/defines used by both Linux and FreeBSD */
-#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-
 #define GTERROR(_l, _f...) xtl_log(_l, XTL_ERROR, errno, "gnttab", _f)
 #define GSERROR(_l, _f...) xtl_log(_l, XTL_ERROR, errno, "gntshr", _f)
 
index f0a4b2c61699759f11b93d83155f2c183de4bb9c..40b5baecdec86c1b92ffb772428571ecb6d6b232 100644 (file)
@@ -95,7 +95,6 @@ typedef uint64_t x86_pgentry_t;
 #define PAGE_SIZE_X86           (1UL << PAGE_SHIFT_X86)
 #define PAGE_MASK_X86           (~(PAGE_SIZE_X86-1))
 
-#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
 #define NRPAGES(x) (ROUNDUP(x, PAGE_SHIFT) >> PAGE_SHIFT)
 
 
index 94a23179d30aed4ecfa01e7be29e25fbdb2b3679..c63d0686fd79f64a0d08cd4b029d99782757d509 100644 (file)
 #define MB(_mb)     (_AC(_mb, ULL) << 20)
 #define GB(_gb)     (_AC(_gb, ULL) << 30)
 
-#define ROUNDUP(_val, _order)                                           \
-    (((unsigned long)(_val)+(1UL<<(_order))-1) & ~((1UL<<(_order))-1))
-
 #define DIV_ROUNDUP(n, d) (((n) + (d) - 1) / (d))
 
 #define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
index 7bd959f28b3998050273e4fc04c67c5275b0234c..9700772d403b855d781f95c45dff56ff6dc4023f 100644 (file)
@@ -73,8 +73,6 @@ static unsigned int nr_fds;
 static int sock = -1;
 static int ro_sock = -1;
 
-#define ROUNDUP(_x, _w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
-
 static bool verbose = false;
 LIST_HEAD(connections);
 int tracefd = -1;