aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Graf <tgraf@noironetworks.com>2014-12-15 14:10:38 +0100
committerThomas Graf <tgraf@noironetworks.com>2014-12-15 14:15:08 +0100
commit8c7be52d10a1e9a4745249a4a94540df13d847a3 (patch)
tree79a802edc2f9bf0bae77cd9d5d919f69dde640db
parentd668c4a94192269235510fa7d23e324ed1155a78 (diff)
lib: Expose SAT_MUT as OVS_SAT_MUL in <openvswitch/util.h>
Insted of exposing the full sat-math.h API, only the macros used in headers is exposed through <openvswitch/util.h> Signed-off-by: Thomas Graf <tgraf@noironetworks.com> Acked-by: Ben Pfaff <blp@nicira.com>
-rw-r--r--include/openvswitch/util.h6
-rw-r--r--lib/sat-math.h8
-rw-r--r--lib/vlog.h2
3 files changed, 9 insertions, 7 deletions
diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
index b0b9935ef..683f76ba3 100644
--- a/include/openvswitch/util.h
+++ b/include/openvswitch/util.h
@@ -40,6 +40,12 @@ const char *ovs_get_program_version(void);
#define OVS_STRINGIZE(ARG) OVS_STRINGIZE2(ARG)
#define OVS_STRINGIZE2(ARG) #ARG
+/* Saturating multiplication of "unsigned int"s: overflow yields UINT_MAX. */
+#define OVS_SAT_MUL(X, Y) \
+ ((Y) == 0 ? 0 \
+ : (X) <= UINT_MAX / (Y) ? (unsigned int) (X) * (unsigned int) (Y) \
+ : UINT_MAX)
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/sat-math.h b/lib/sat-math.h
index 3d1c50bdc..beeff8b2b 100644
--- a/lib/sat-math.h
+++ b/lib/sat-math.h
@@ -18,6 +18,7 @@
#define SAT_MATH_H 1
#include <limits.h>
+#include "openvswitch/util.h"
/* Saturating addition: overflow yields UINT_MAX. */
static inline unsigned int
@@ -33,15 +34,10 @@ sat_sub(unsigned int x, unsigned int y)
return x >= y ? x - y : 0;
}
-/* Saturating multiplication of "unsigned int"s: overflow yields UINT_MAX. */
-#define SAT_MUL(X, Y) \
- ((Y) == 0 ? 0 \
- : (X) <= UINT_MAX / (Y) ? (unsigned int) (X) * (unsigned int) (Y) \
- : UINT_MAX)
static inline unsigned int
sat_mul(unsigned int x, unsigned int y)
{
- return SAT_MUL(x, y);
+ return OVS_SAT_MUL(x, y);
}
#endif /* sat-math.h */
diff --git a/lib/vlog.h b/lib/vlog.h
index 67d37eb9f..8190a44b7 100644
--- a/lib/vlog.h
+++ b/lib/vlog.h
@@ -116,7 +116,7 @@ struct vlog_rate_limit {
* messages per minute and a maximum burst size of BURST messages. */
#define VLOG_RATE_LIMIT_INIT(RATE, BURST) \
{ \
- TOKEN_BUCKET_INIT(RATE, SAT_MUL(BURST, VLOG_MSG_TOKENS)), \
+ TOKEN_BUCKET_INIT(RATE, OVS_SAT_MUL(BURST, VLOG_MSG_TOKENS)),\
0, /* first_dropped */ \
0, /* last_dropped */ \
0, /* n_dropped */ \