diff mbox

PR libitm/70456: Allocate aligned memory in gtm_thread operator new

Message ID 20160330123453.GA17104@intel.com
State New
Headers show

Commit Message

H.J. Lu March 30, 2016, 12:34 p.m. UTC
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 mbox

Patch

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;