Skip to content

Commit

Permalink
ofp-actions: Factor OFPACT_PADDED_MEMBERS out into a more general form.
Browse files Browse the repository at this point in the history
This makes it easier to reuse this idea elsewhere.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Ryan Moats <[email protected]>
  • Loading branch information
blp committed Aug 8, 2016
1 parent 0763bf0 commit 7b51295
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
14 changes: 1 addition & 13 deletions include/openvswitch/ofp-actions.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,7 @@ BUILD_ASSERT_DECL(sizeof(struct ofpact) == 4);
/* Alignment. */
#define OFPACT_ALIGNTO 8
#define OFPACT_ALIGN(SIZE) ROUND_UP(SIZE, OFPACT_ALIGNTO)

/* Expands to an anonymous union that contains:
*
* - MEMBERS in a nested anonymous struct.
*
* - An array as large as MEMBERS plus padding to a multiple of 8 bytes.
*
* The effect is to pad MEMBERS to a multiple of 8 bytes. */
#define OFPACT_PADDED_MEMBERS(MEMBERS) \
union { \
struct { MEMBERS }; \
uint8_t pad[OFPACT_ALIGN(sizeof(struct { MEMBERS }))]; \
}
#define OFPACT_PADDED_MEMBERS(MEMBERS) PADDED_MEMBERS(OFPACT_ALIGNTO, MEMBERS)

/* Returns the ofpact following 'ofpact'. */
static inline struct ofpact *
Expand Down
22 changes: 21 additions & 1 deletion include/openvswitch/util.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -162,6 +162,26 @@ OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char *);
/* Returns true if X is a power of 2, otherwise false. */
#define IS_POW2(X) ((X) && !((X) & ((X) - 1)))

/* Expands to an anonymous union that contains:
*
* - MEMBERS in a nested anonymous struct.
*
* - An array as large as MEMBERS plus padding to a multiple of UNIT bytes.
*
* The effect is to pad MEMBERS to a multiple of UNIT bytes.
*
* For example, the struct below is 8 bytes long, with 6 bytes of padding:
*
* struct padded_struct {
* PADDED_MEMBERS(8, uint8_t x; uint8_t y;);
* };
*/
#define PADDED_MEMBERS(UNIT, MEMBERS) \
union { \
struct { MEMBERS }; \
uint8_t pad[ROUND_UP(sizeof(struct { MEMBERS }), UNIT)]; \
}

static inline bool
is_pow2(uintmax_t x)
{
Expand Down

0 comments on commit 7b51295

Please sign in to comment.