diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-05-28 17:57:17 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-05-28 17:57:17 +0000 |
commit | 09c314e5580b54ae6adc9bc321bd0827e4f1e25b (patch) | |
tree | ca3bdbfbbedb8202282f110fcb7217c4812d7d0d | |
parent | ebc6312a86c53cfbb70496fd793e0b0a668b236c (diff) | |
download | mpfr-09c314e5580b54ae6adc9bc321bd0827e4f1e25b.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).
(merged changeset r9466 from the trunk)
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/3.1@9467 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/mpfr-gmp.c | 6 | ||||
-rw-r--r-- | src/mpfr-gmp.h | 14 | ||||
-rw-r--r-- | src/mpfr-impl.h | 14 |
3 files changed, 17 insertions, 17 deletions
diff --git a/src/mpfr-gmp.c b/src/mpfr-gmp.c index 75c3f1327..893b2e495 100644 --- a/src/mpfr-gmp.c +++ b/src/mpfr-gmp.c @@ -314,9 +314,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; #endif diff --git a/src/mpfr-gmp.h b/src/mpfr-gmp.h index c3d4b22c5..b1862ffe7 100644 --- a/src/mpfr-gmp.h +++ b/src/mpfr-gmp.h @@ -262,15 +262,17 @@ typedef __gmp_randstate_struct *gmp_randstate_ptr; #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)); #endif diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h index 50e90f8df..957f98e9a 100644 --- a/src/mpfr-impl.h +++ b/src/mpfr-impl.h @@ -62,7 +62,12 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., # include "config.h" #endif -#ifdef MPFR_HAVE_GMP_IMPL /* Build with gmp internals*/ +/* 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 */ # ifndef __GMP_H__ # include "gmp.h" @@ -104,13 +109,6 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., # define mpn_sqr_n(dst,src,n) mpn_mul((dst),(src),(n),(src),(n)) #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. - If the use of detection macros is needed in the future, this could be - moved below (after the detection macros are defined). */ -#include "mpfr-thread.h" - /****************************************************** ***************** Detection macros ******************* |