summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-05-28 11:11:31 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2015-05-28 11:11:31 +0000
commitc73d5d6d548ad99ada57b507e1ea19a7bcfbb519 (patch)
treefdd98fcdf5e1f4608be726f6c283f40bd6f43584
parent24cfcf1086269fd2372d4145df694a43cd1ed428 (diff)
downloadmpfr-c73d5d6d548ad99ada57b507e1ea19a7bcfbb519.tar.gz
[src] Fixed allocation issue for multithreaded applications:
https://sympa.inria.fr/sympa/arc/mpfr/2015-05/msg00001.html * mpfr-gmp.{c,h}: made mpfr_allocate_func, mpfr_reallocate_func and mpfr_free_func thread-local; updated MPFR_GET_MEMFUNC to execute mp_get_memory_functions only when these pointers have not been set to the actual function pointers yet. * mpfr-impl.h: #include "mpfr-thread.h" earlier (before mpfr-gmp.h, where MPFR_THREAD_ATTR is now used). git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9466 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/mpfr-gmp.c6
-rw-r--r--src/mpfr-gmp.h14
-rw-r--r--src/mpfr-impl.h10
3 files changed, 16 insertions, 14 deletions
diff --git a/src/mpfr-gmp.c b/src/mpfr-gmp.c
index da0ebd84f..0c8b85219 100644
--- a/src/mpfr-gmp.c
+++ b/src/mpfr-gmp.c
@@ -307,9 +307,9 @@ mpfr_assert_fail (const char *filename, int linenum,
and http://software.intel.com/en-us/articles/intelr-fortran-compiler-for-mac-os-non_lazy_ptr-unresolved-references-from-linking
Note that using ranlib -c or libtool -c is another fix.
*/
-void * (*mpfr_allocate_func) (size_t) = 0;
-void * (*mpfr_reallocate_func) (void *, size_t, size_t) = 0;
-void (*mpfr_free_func) (void *, size_t) = 0;
+MPFR_THREAD_ATTR void * (*mpfr_allocate_func) (size_t) = 0;
+MPFR_THREAD_ATTR void * (*mpfr_reallocate_func) (void *, size_t, size_t) = 0;
+MPFR_THREAD_ATTR void (*mpfr_free_func) (void *, size_t) = 0;
void *
mpfr_tmp_allocate (struct tmp_marker **tmp_marker, size_t size)
diff --git a/src/mpfr-gmp.h b/src/mpfr-gmp.h
index a7e516590..dbed72267 100644
--- a/src/mpfr-gmp.h
+++ b/src/mpfr-gmp.h
@@ -259,15 +259,17 @@ __MPFR_DECLSPEC extern const struct bases mpfr_bases[257];
#undef __gmp_allocate_func
#undef __gmp_reallocate_func
#undef __gmp_free_func
-#define MPFR_GET_MEMFUNC mp_get_memory_functions(&mpfr_allocate_func, &mpfr_reallocate_func, &mpfr_free_func)
+#define MPFR_GET_MEMFUNC \
+ ((void) (MPFR_LIKELY (mpfr_allocate_func != 0) || \
+ (mp_get_memory_functions(&mpfr_allocate_func, \
+ &mpfr_reallocate_func, \
+ &mpfr_free_func), 1)))
#define __gmp_allocate_func (MPFR_GET_MEMFUNC, mpfr_allocate_func)
#define __gmp_reallocate_func (MPFR_GET_MEMFUNC, mpfr_reallocate_func)
#define __gmp_free_func (MPFR_GET_MEMFUNC, mpfr_free_func)
-__MPFR_DECLSPEC extern void * (*mpfr_allocate_func) _MPFR_PROTO ((size_t));
-__MPFR_DECLSPEC extern void * (*mpfr_reallocate_func) _MPFR_PROTO ((void *,
- size_t, size_t));
-__MPFR_DECLSPEC extern void (*mpfr_free_func) _MPFR_PROTO ((void *,
- size_t));
+__MPFR_DECLSPEC extern MPFR_THREAD_ATTR void * (*mpfr_allocate_func) _MPFR_PROTO ((size_t));
+__MPFR_DECLSPEC extern MPFR_THREAD_ATTR void * (*mpfr_reallocate_func) _MPFR_PROTO ((void *, size_t, size_t));
+__MPFR_DECLSPEC extern MPFR_THREAD_ATTR void (*mpfr_free_func) _MPFR_PROTO ((void *, size_t));
#if defined(WANT_GMP_INTERNALS) && defined(HAVE___GMPN_ROOTREM)
#ifndef __gmpn_rootrem
diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h
index 0caec6f18..97cd869b3 100644
--- a/src/mpfr-impl.h
+++ b/src/mpfr-impl.h
@@ -70,6 +70,11 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
# include "config.h"
#endif
+/* For the definition of MPFR_THREAD_ATTR. GCC/ICC detection macros are
+ no longer used, as they sometimes gave incorrect information about
+ the support of thread-local variables. A configure check is now done. */
+#include "mpfr-thread.h"
+
#ifdef MPFR_HAVE_GMP_IMPL /* Build with gmp internals */
# include "gmp.h"
@@ -125,11 +130,6 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
************** Attributes definition *****************
******************************************************/
-/* For the definition of MPFR_THREAD_ATTR. GCC/ICC detection macros are
- no longer used, as they sometimes gave incorrect information about
- the support of thread-local variables. A configure check is now done. */
-#include "mpfr-thread.h"
-
#if defined(MPFR_HAVE_NORETURN)
/* _Noreturn is specified by ISO C11 (Section 6.7.4);
in GCC, it is supported as of version 4.7. */