aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Soheil Hassas Yeganeh <soheil@google.com>2018-10-19 14:23:04 -0400
committerGravatar Soheil Hassas Yeganeh <soheil@google.com>2018-10-19 14:23:04 -0400
commit58a85ffc5e33b2867280906605d94dfcb3c888b5 (patch)
tree0ff1808aee93efdedf856c810931dc549f6b4930
parent1f85f6ba33af282530e28c8e6a7dbaae0da8faed (diff)
Use union to make alignement robust.
Suggested-by: vjpai@google.com
-rw-r--r--src/core/lib/gpr/mpscq.h6
-rw-r--r--src/core/lib/iomgr/ev_epoll1_linux.cc10
2 files changed, 11 insertions, 5 deletions
diff --git a/src/core/lib/gpr/mpscq.h b/src/core/lib/gpr/mpscq.h
index dac2801b4e..5ded2522bd 100644
--- a/src/core/lib/gpr/mpscq.h
+++ b/src/core/lib/gpr/mpscq.h
@@ -38,9 +38,11 @@ typedef struct gpr_mpscq_node {
// Actual queue type
typedef struct gpr_mpscq {
- gpr_atm head;
// make sure head & tail don't share a cacheline
- char padding[GPR_CACHELINE_SIZE - sizeof(head)];
+ union {
+ char padding[GPR_CACHELINE_SIZE];
+ gpr_atm head;
+ };
gpr_mpscq_node* tail;
gpr_mpscq_node stub;
} gpr_mpscq;
diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc
index 0f58b4a63e..38571b1957 100644
--- a/src/core/lib/iomgr/ev_epoll1_linux.cc
+++ b/src/core/lib/iomgr/ev_epoll1_linux.cc
@@ -193,9 +193,13 @@ struct grpc_pollset_worker {
#define MAX_NEIGHBORHOODS 1024
typedef struct pollset_neighborhood {
- gpr_mu mu;
- grpc_pollset* active_root;
- char pad[GPR_CACHELINE_SIZE - sizeof(mu) - sizeof(active_root)];
+ union {
+ char pad[GPR_CACHELINE_SIZE];
+ struct {
+ gpr_mu mu;
+ grpc_pollset* active_root;
+ };
+ };
} pollset_neighborhood;
struct grpc_pollset {