X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=libitm%2Futil.cc;h=522a9b043dbf181ee827c2837275ff6631976684;hb=d4920f402af2591fa9864863f8c4ddcad1f9ebc1;hp=bd2024cce8359dfd687b61cb84fd8ad64cac7cb3;hpb=75f9527c9b8910651e5c1fab56ee0698376f2217;p=gcc.git diff --git a/libitm/util.cc b/libitm/util.cc index bd2024cce83..522a9b043db 100644 --- a/libitm/util.cc +++ b/libitm/util.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2009-2013 Free Software Foundation, Inc. +/* Copyright (C) 2009-2018 Free Software Foundation, Inc. Contributed by Richard Henderson . 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; }