This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]