Add a new QUIC platform API quic_aligned.h for the alignment macro definitions.

Merge internal change: 142807099

Review-Url: https://codereview.chromium.org/2599143003
Cr-Commit-Position: refs/heads/master@{#440725}
diff --git a/net/net.gypi b/net/net.gypi
index 21eb7b82..a5fd9f0 100644
--- a/net/net.gypi
+++ b/net/net.gypi
@@ -1205,8 +1205,10 @@
       'quic/core/quic_write_blocked_list.h',
       'quic/core/spdy_utils.cc',
       'quic/core/spdy_utils.h',
+      'quic/platform/api/quic_aligned.h',
       'quic/platform/api/quic_clock.cc',
       'quic/platform/api/quic_clock.h',
+      'quic/platform/api/quic_export.h',
       'quic/platform/api/quic_ip_address_family.h',
       'quic/platform/api/quic_ip_address.cc',
       'quic/platform/api/quic_ip_address.h',
@@ -1216,8 +1218,10 @@
       'quic/platform/api/quic_socket_address.cc',
       'quic/platform/api/quic_socket_address.h',
       'quic/platform/api/quic_str_cat.h',
+      'quic/platform/impl/quic_aligned_impl.h',
       'quic/platform/impl/quic_chromium_clock.cc',
       'quic/platform/impl/quic_chromium_clock.h',
+      'quic/platform/impl/quic_export_impl.h',
       'quic/platform/impl/quic_ip_address_impl.cc',
       'quic/platform/impl/quic_ip_address_impl.h',
       'quic/platform/impl/quic_mutex_impl.cc',
diff --git a/net/quic/core/crypto/aead_base_encrypter.cc b/net/quic/core/crypto/aead_base_encrypter.cc
index 3d8c24e..fa8eab9 100644
--- a/net/quic/core/crypto/aead_base_encrypter.cc
+++ b/net/quic/core/crypto/aead_base_encrypter.cc
@@ -6,8 +6,8 @@
 
 #include <string>
 
-#include "net/quic/core/quic_types.h"
 #include "net/quic/core/quic_utils.h"
+#include "net/quic/platform/api/quic_aligned.h"
 #include "third_party/boringssl/src/include/openssl/err.h"
 #include "third_party/boringssl/src/include/openssl/evp.h"
 
diff --git a/net/quic/core/quic_arena_scoped_ptr.h b/net/quic/core/quic_arena_scoped_ptr.h
index 4b8ce6a..5fb8fac 100644
--- a/net/quic/core/quic_arena_scoped_ptr.h
+++ b/net/quic/core/quic_arena_scoped_ptr.h
@@ -15,7 +15,7 @@
 
 #include "base/logging.h"
 #include "base/macros.h"
-#include "net/quic/core/quic_types.h"
+#include "net/quic/platform/api/quic_aligned.h"
 
 namespace net {
 
diff --git a/net/quic/core/quic_framer.cc b/net/quic/core/quic_framer.cc
index f90a01e..eba9bff 100644
--- a/net/quic/core/quic_framer.cc
+++ b/net/quic/core/quic_framer.cc
@@ -24,6 +24,7 @@
 #include "net/quic/core/quic_flags.h"
 #include "net/quic/core/quic_socket_address_coder.h"
 #include "net/quic/core/quic_utils.h"
+#include "net/quic/platform/api/quic_aligned.h"
 
 using base::ContainsKey;
 using base::StringPiece;
@@ -531,10 +532,7 @@
   } else if (packet.length() <= kMaxPacketSize) {
     // The optimized decryption algorithm implementations run faster when
     // operating on aligned memory.
-    //
-    // TODO(rtenneti): Change the default 64 alignas value (used the default
-    // value from CACHELINE_SIZE).
-    ALIGNAS(64) char buffer[kMaxPacketSize];
+    QUIC_CACHELINE_ALIGNED char buffer[kMaxPacketSize];
     rv = ProcessDataPacket(&reader, public_header, packet, buffer,
                            kMaxPacketSize);
   } else {
diff --git a/net/quic/core/quic_packet_creator.cc b/net/quic/core/quic_packet_creator.cc
index c22bad53..cee8ca44 100644
--- a/net/quic/core/quic_packet_creator.cc
+++ b/net/quic/core/quic_packet_creator.cc
@@ -14,6 +14,7 @@
 #include "net/quic/core/quic_data_writer.h"
 #include "net/quic/core/quic_flags.h"
 #include "net/quic/core/quic_utils.h"
+#include "net/quic/platform/api/quic_aligned.h"
 
 using base::StringPiece;
 using std::string;
@@ -313,9 +314,7 @@
     return;
   }
 
-  // TODO(rtenneti): Change the default 64 alignas value (used the default
-  // value from CACHELINE_SIZE).
-  ALIGNAS(64) char seralized_packet_buffer[kMaxPacketSize];
+  QUIC_CACHELINE_ALIGNED char seralized_packet_buffer[kMaxPacketSize];
   SerializePacket(seralized_packet_buffer, kMaxPacketSize);
   OnSerializedPacket();
 }
@@ -360,7 +359,7 @@
   // Write out the packet header
   QuicPacketHeader header;
   FillPacketHeader(&header);
-  ALIGNAS(64) char encrypted_buffer[kMaxPacketSize];
+  QUIC_CACHELINE_ALIGNED char encrypted_buffer[kMaxPacketSize];
   QuicDataWriter writer(arraysize(encrypted_buffer), encrypted_buffer);
   if (!framer_->AppendPacketHeader(header, &writer)) {
     QUIC_BUG << "AppendPacketHeader failed";
diff --git a/net/quic/core/quic_types.h b/net/quic/core/quic_types.h
index b11d2c4..30fefd2 100644
--- a/net/quic/core/quic_types.h
+++ b/net/quic/core/quic_types.h
@@ -14,16 +14,6 @@
 #include "net/quic/core/quic_time.h"
 #include "net/quic/platform/api/quic_export.h"
 
-#ifdef _MSC_VER
-// MSVC 2013 and prior don't have alignof or aligned(); they have __alignof and
-// a __declspec instead.
-#define QUIC_ALIGN_OF __alignof
-#define QUIC_ALIGNED(X) __declspec(align(X))
-#else
-#define QUIC_ALIGN_OF alignof
-#define QUIC_ALIGNED(X) __attribute__((aligned(X)))
-#endif  // _MSC_VER
-
 namespace net {
 
 typedef uint8_t QuicPathId;
diff --git a/net/quic/platform/api/quic_aligned.h b/net/quic/platform/api/quic_aligned.h
new file mode 100644
index 0000000..7e5d935
--- /dev/null
+++ b/net/quic/platform/api/quic_aligned.h
@@ -0,0 +1,14 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_QUIC_PLATFORM_API_QUIC_ALIGNED_H_
+#define NET_QUIC_PLATFORM_API_QUIC_ALIGNED_H_
+
+#include "net/quic/platform/impl/quic_aligned_impl.h"
+
+#define QUIC_ALIGN_OF QUIC_ALIGN_OF_IMPL
+#define QUIC_ALIGNED(X) QUIC_ALIGNED_IMPL(X)
+#define QUIC_CACHELINE_ALIGNED QUIC_CACHELINE_ALIGNED_IMPL
+
+#endif  // NET_QUIC_PLATFORM_API_QUIC_ALIGNED_H_
diff --git a/net/quic/platform/impl/quic_aligned_impl.h b/net/quic/platform/impl/quic_aligned_impl.h
new file mode 100644
index 0000000..eec157c
--- /dev/null
+++ b/net/quic/platform/impl/quic_aligned_impl.h
@@ -0,0 +1,22 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_QUIC_PLATFORM_IMPL_QUIC_ALIGNED_IMPL_H_
+#define NET_QUIC_PLATFORM_IMPL_QUIC_ALIGNED_IMPL_H_
+
+#ifdef _MSC_VER
+// MSVC 2013 and prior don't have alignof or aligned(); they have __alignof and
+// a __declspec instead.
+#define QUIC_ALIGN_OF_IMPL __alignof
+#define QUIC_ALIGNED_IMPL(X) __declspec(align(X))
+#else
+#define QUIC_ALIGN_OF_IMPL alignof
+#define QUIC_ALIGNED_IMPL(X) __attribute__((aligned(X)))
+#endif  // _MSC_VER
+
+// TODO(rtenneti): Change the default 64 alignas value (used the default
+// value from CACHELINE_SIZE).
+#define QUIC_CACHELINE_ALIGNED_IMPL ALIGNAS(64)
+
+#endif  // NET_QUIC_PLATFORM_IMPL_QUIC_ALIGNED_IMPL_H_