This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR libitm/70456: Allocate aligned memory in gtm_thread operator new
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: triegel at redhat dot com
- Date: Wed, 30 Mar 2016 05:34:53 -0700
- Subject: [PATCH] PR libitm/70456: Allocate aligned memory in gtm_thread operator new
- Authentication-results: sourceware.org; auth=none
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Since GTM::gtm_thread has
gtm_thread *next_thread __attribute__((__aligned__(HW_CACHELINE_SIZE)));
GTM::gtm_thread::operator new should allocate aligned memory.
Tested on Linux/x86-64. OK for trunk.
H.J.
----
PR libitm/70456
* beginend.cc (GTM::gtm_thread::operator new): Use posix_memalign
to allocate aligned memory.
---
libitm/beginend.cc | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/libitm/beginend.cc b/libitm/beginend.cc
index 20b5547..e2a8327 100644
--- a/libitm/beginend.cc
+++ b/libitm/beginend.cc
@@ -63,7 +63,14 @@ GTM::gtm_thread::operator new (size_t s)
assert(s == sizeof(gtm_thread));
+#ifdef HAVE_POSIX_MEMALIGN
+ if (posix_memalign (&tx, __alignof__ (gtm_thread), sizeof (gtm_thread)))
+ GTM_fatal ("Out of memory allocating %lu bytes aligned at %lu bytes",
+ (unsigned long) sizeof (gtm_thread),
+ (unsigned long) __alignof__ (gtm_thread));
+#else
tx = xmalloc (sizeof (gtm_thread), true);
+#endif
memset (tx, 0, sizeof (gtm_thread));
return tx;
--
2.5.5