aboutsummaryrefslogtreecommitdiff
path: root/libitm
diff options
context:
space:
mode:
authorTorvald Riegel <triegel@redhat.com>2012-02-14 13:13:56 +0000
committerTorvald Riegel <torvald@gcc.gnu.org>2012-02-14 13:13:56 +0000
commit7d33bcb73866d5310b4eb190172240bcb71f51f6 (patch)
tree3f757ed98c58cd9c6de39c80072caa8625239a50 /libitm
parentdd552284fd817c9d946598a7b647f9e67753bed6 (diff)
downloadgcc-7d33bcb73866d5310b4eb190172240bcb71f51f6.zip
gcc-7d33bcb73866d5310b4eb190172240bcb71f51f6.tar.gz
gcc-7d33bcb73866d5310b4eb190172240bcb71f51f6.tar.bz2
libitm: Add xcalloc.
libitm/ * util.cc (GTM::xcalloc): New. * common.h (GTM::xcalloc): Declare. From-SVN: r184210
Diffstat (limited to 'libitm')
-rw-r--r--libitm/ChangeLog5
-rw-r--r--libitm/common.h2
-rw-r--r--libitm/util.cc12
3 files changed, 19 insertions, 0 deletions
diff --git a/libitm/ChangeLog b/libitm/ChangeLog
index decdad3..130c9ef 100644
--- a/libitm/ChangeLog
+++ b/libitm/ChangeLog
@@ -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.
diff --git a/libitm/common.h b/libitm/common.h
index 14d0efb4..b1ef2d4 100644
--- a/libitm/common.h
+++ b/libitm/common.h
@@ -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));
diff --git a/libitm/util.cc b/libitm/util.cc
index afd37e4..48a1bf8 100644
--- a/libitm/util.cc
+++ b/libitm/util.cc
@@ -71,6 +71,18 @@ xmalloc (size_t size, bool separate_cl)
}
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)
{
// TODO Use posix_memalign if separate_cl is true, or some other allocation