[PR86438] compare-elim: cope with set of in_b
[gcc.git] / libitm / util.cc
index bd2024cce8359dfd687b61cb84fd8ad64cac7cb3..522a9b043dbf181ee827c2837275ff6631976684 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2009-2013 Free Software Foundation, Inc.
+/* Copyright (C) 2009-2018 Free Software Foundation, Inc.
    Contributed by Richard Henderson <rth@redhat.com>.
 
    This file is part of the GNU Transactional Memory Library (libitm).
@@ -61,12 +61,22 @@ GTM_fatal (const char *fmt, ...)
 void *
 xmalloc (size_t size, bool separate_cl)
 {
-  // TODO Use posix_memalign if separate_cl is true, or some other allocation
-  // method that will avoid sharing cache lines with data used by other
-  // threads.
-  void *r = malloc (size);
-  if (r == 0)
-    GTM_fatal ("Out of memory allocating %lu bytes", (unsigned long) size);
+  void *r;
+#ifdef HAVE_POSIX_MEMALIGN
+  if (separate_cl)
+    {
+      if (posix_memalign (&r, HW_CACHELINE_SIZE, size))
+       GTM_fatal ("Out of memory allocating %lu bytes aligned on cache line",
+                  (unsigned long) size);
+    }
+  else
+#endif
+    {
+      r = malloc (size);
+      if (r == 0)
+       GTM_fatal ("Out of memory allocating %lu bytes",
+                  (unsigned long) size);
+    }
   return r;
 }