Skip to content

Commit

Permalink
lib: Expose SAT_MUT as OVS_SAT_MUL in <openvswitch/util.h>
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
Thomas Graf committed Dec 15, 2014
1 parent d668c4a commit 8c7be52
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 6 additions & 0 deletions include/openvswitch/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions lib/sat-math.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
2 changes: 1 addition & 1 deletion lib/vlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ \
Expand Down

0 comments on commit 8c7be52

Please sign in to comment.