[ovs-dev,v3,08/21] Misc cleanup with "util.h" header files
diff mbox

Message ID d74c2a713d5f1d8e17f4ec1bc1d3d913a665ad85.1458586229.git.ben@skyportsystems.com
State Superseded
Headers show

Commit Message

ben@skyportsystems.com March 21, 2016, 6:58 p.m. UTC
From: Ben Warren <ben@skyportsystems.com>

Removed from redundant #includes and moved some macros to different file
scope

Signed-off-by: Ben Warren <ben@skyportsystems.com>
Acked-by: Ryan Moats <rmoats@us.ibm.com>
---
 include/openvswitch/compiler.h |  3 +++
 include/openvswitch/util.h     | 50 ++++++++++++++++++++++++++++++++++++++++-
 lib/util.h                     | 51 ------------------------------------------
 3 files changed, 52 insertions(+), 52 deletions(-)

Patch
diff mbox

diff --git a/include/openvswitch/compiler.h b/include/openvswitch/compiler.h
index 1d3af9f..0e402c0 100644
--- a/include/openvswitch/compiler.h
+++ b/include/openvswitch/compiler.h
@@ -17,6 +17,9 @@ 
 #ifndef OPENVSWITCH_COMPILER_H
 #define OPENVSWITCH_COMPILER_H 1
 
+#include <stddef.h>
+#include <stdbool.h>
+
 #ifndef __has_feature
   #define __has_feature(x) 0
 #endif
diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
index 63c8a45..cfafc36 100644
--- a/include/openvswitch/util.h
+++ b/include/openvswitch/util.h
@@ -17,8 +17,9 @@ 
 #ifndef OPENVSWITCH_UTIL_H
 #define OPENVSWITCH_UTIL_H 1
 
-#include <openvswitch/version.h>
 #include <openvswitch/compiler.h>
+#include <openvswitch/version.h>
+#include <openvswitch/types.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -147,6 +148,53 @@  OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
 #define INIT_CONTAINER(OBJECT, POINTER, MEMBER) \
     ((OBJECT) = NULL, ASSIGN_CONTAINER(OBJECT, POINTER, MEMBER))
 
+/* Returns the number of elements in ARRAY. */
+#define ARRAY_SIZE(ARRAY) __ARRAY_SIZE(ARRAY)
+
+/* Returns X / Y, rounding up.  X must be nonnegative to round correctly. */
+#define DIV_ROUND_UP(X, Y) (((X) + ((Y) - 1)) / (Y))
+
+/* Returns X rounded up to the nearest multiple of Y. */
+#define ROUND_UP(X, Y) (DIV_ROUND_UP(X, Y) * (Y))
+
+/* Returns the least number that, when added to X, yields a multiple of Y. */
+#define PAD_SIZE(X, Y) (ROUND_UP(X, Y) - (X))
+
+/* Returns X rounded down to the nearest multiple of Y. */
+#define ROUND_DOWN(X, Y) ((X) / (Y) * (Y))
+
+/* Returns true if X is a power of 2, otherwise false. */
+#define IS_POW2(X) ((X) && !((X) & ((X) - 1)))
+
+static inline bool
+is_pow2(uintmax_t x)
+{
+    return IS_POW2(x);
+}
+
+/* Returns X rounded up to a power of 2.  X must be a constant expression. */
+#define ROUND_UP_POW2(X) RUP2__(X)
+#define RUP2__(X) (RUP2_1(X) + 1)
+#define RUP2_1(X) (RUP2_2(X) | (RUP2_2(X) >> 16))
+#define RUP2_2(X) (RUP2_3(X) | (RUP2_3(X) >> 8))
+#define RUP2_3(X) (RUP2_4(X) | (RUP2_4(X) >> 4))
+#define RUP2_4(X) (RUP2_5(X) | (RUP2_5(X) >> 2))
+#define RUP2_5(X) (RUP2_6(X) | (RUP2_6(X) >> 1))
+#define RUP2_6(X) ((X) - 1)
+
+/* Returns X rounded down to a power of 2.  X must be a constant expression. */
+#define ROUND_DOWN_POW2(X) RDP2__(X)
+#define RDP2__(X) (RDP2_1(X) - (RDP2_1(X) >> 1))
+#define RDP2_1(X) (RDP2_2(X) | (RDP2_2(X) >> 16))
+#define RDP2_2(X) (RDP2_3(X) | (RDP2_3(X) >> 8))
+#define RDP2_3(X) (RDP2_4(X) | (RDP2_4(X) >> 4))
+#define RDP2_4(X) (RDP2_5(X) | (RDP2_5(X) >> 2))
+#define RDP2_5(X) (      (X) | (      (X) >> 1))
+
+/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to
+ * (void *). This is to suppress the alignment warning issued by clang. */
+#define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR))
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/util.h b/lib/util.h
index 41c5ea6..5dcb5df 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -20,15 +20,10 @@ 
 #include <arpa/inet.h>
 #include <inttypes.h>
 #include <limits.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "compiler.h"
-#include "openvswitch/types.h"
 #include "openvswitch/util.h"
 
 #ifndef va_copy
@@ -56,48 +51,6 @@  extern char *program_name;
 #define __ARRAY_SIZE(ARRAY) __ARRAY_SIZE_NOCHECK(ARRAY)
 #endif
 
-/* Returns the number of elements in ARRAY. */
-#define ARRAY_SIZE(ARRAY) __ARRAY_SIZE(ARRAY)
-
-/* Returns X / Y, rounding up.  X must be nonnegative to round correctly. */
-#define DIV_ROUND_UP(X, Y) (((X) + ((Y) - 1)) / (Y))
-
-/* Returns X rounded up to the nearest multiple of Y. */
-#define ROUND_UP(X, Y) (DIV_ROUND_UP(X, Y) * (Y))
-
-/* Returns the least number that, when added to X, yields a multiple of Y. */
-#define PAD_SIZE(X, Y) (ROUND_UP(X, Y) - (X))
-
-/* Returns X rounded down to the nearest multiple of Y. */
-#define ROUND_DOWN(X, Y) ((X) / (Y) * (Y))
-
-/* Returns true if X is a power of 2, otherwise false. */
-#define IS_POW2(X) ((X) && !((X) & ((X) - 1)))
-
-static inline bool
-is_pow2(uintmax_t x)
-{
-    return IS_POW2(x);
-}
-
-/* Returns X rounded up to a power of 2.  X must be a constant expression. */
-#define ROUND_UP_POW2(X) RUP2__(X)
-#define RUP2__(X) (RUP2_1(X) + 1)
-#define RUP2_1(X) (RUP2_2(X) | (RUP2_2(X) >> 16))
-#define RUP2_2(X) (RUP2_3(X) | (RUP2_3(X) >> 8))
-#define RUP2_3(X) (RUP2_4(X) | (RUP2_4(X) >> 4))
-#define RUP2_4(X) (RUP2_5(X) | (RUP2_5(X) >> 2))
-#define RUP2_5(X) (RUP2_6(X) | (RUP2_6(X) >> 1))
-#define RUP2_6(X) ((X) - 1)
-
-/* Returns X rounded down to a power of 2.  X must be a constant expression. */
-#define ROUND_DOWN_POW2(X) RDP2__(X)
-#define RDP2__(X) (RDP2_1(X) - (RDP2_1(X) >> 1))
-#define RDP2_1(X) (RDP2_2(X) | (RDP2_2(X) >> 16))
-#define RDP2_2(X) (RDP2_3(X) | (RDP2_3(X) >> 8))
-#define RDP2_3(X) (RDP2_4(X) | (RDP2_4(X) >> 4))
-#define RDP2_4(X) (RDP2_5(X) | (RDP2_5(X) >> 2))
-#define RDP2_5(X) (      (X) | (      (X) >> 1))
 
 /* This system's cache line size, in bytes.
  * Being wrong hurts performance but not correctness. */
@@ -125,10 +78,6 @@  ovs_prefetch_range(const void *start, size_t size)
 
 #define OVS_NOT_REACHED() abort()
 
-/* Given ATTR, and TYPE, cast the ATTR to TYPE by first casting ATTR to
- * (void *). This is to suppress the alignment warning issued by clang. */
-#define ALIGNED_CAST(TYPE, ATTR) ((TYPE) (void *) (ATTR))
-
 /* Use "%"PRIuSIZE to format size_t with printf(). */
 #ifdef _WIN32
 #define PRIdSIZE "Id"