libitm: Add xcalloc.
authorTorvald Riegel <triegel@redhat.com>
Tue, 14 Feb 2012 13:13:56 +0000 (13:13 +0000)
committerTorvald Riegel <torvald@gcc.gnu.org>
Tue, 14 Feb 2012 13:13:56 +0000 (13:13 +0000)
libitm/
* util.cc (GTM::xcalloc): New.
* common.h (GTM::xcalloc): Declare.

From-SVN: r184210

libitm/ChangeLog
libitm/common.h
libitm/util.cc

index decdad3c68c9d871016edb8d60309c13f831b570..130c9efbd8500c12ed3c22767a401f3446310c3f 100644 (file)
@@ -1,3 +1,8 @@
+2012-02-14  Torvald Riegel  <triegel@redhat.com>
+
+       * util.cc (GTM::xcalloc): New.
+       * common.h (GTM::xcalloc): Declare.
+
 2012-02-14  Eric Botcazou  <ebotcazou@adacore.com>
 
        * config/sparc/target.h (cpu_relax): Read from CC register.
index 14d0efb40ba8dcb9d76e08f8a909476aa3c039af..b1ef2d4e63ad83c4d874fe764ad12d8bc0c951aa 100644 (file)
@@ -54,6 +54,8 @@ namespace GTM HIDDEN {
 // cache lines that are not shared with any object used by another thread.
 extern void * xmalloc (size_t s, bool separate_cl = false)
   __attribute__((malloc, nothrow));
+extern void * xcalloc (size_t s, bool separate_cl = false)
+  __attribute__((malloc, nothrow));
 extern void * xrealloc (void *p, size_t s, bool separate_cl = false)
   __attribute__((malloc, nothrow));
 
index afd37e41731a4a058992d46e685ceccd37c2d83c..48a1bf88d7cb1e52976f7d63e1f43cd1617fae4a 100644 (file)
@@ -70,6 +70,18 @@ xmalloc (size_t size, bool separate_cl)
   return r;
 }
 
+void *
+xcalloc (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 = calloc (1, size);
+  if (r == 0)
+    GTM_fatal ("Out of memory allocating %lu bytes", (unsigned long) size);
+  return r;
+}
+
 void *
 xrealloc (void *old, size_t size, bool separate_cl)
 {