diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-05-28 11:11:31 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-05-28 11:11:31 +0000 |
commit | c73d5d6d548ad99ada57b507e1ea19a7bcfbb519 (patch) | |
tree | fdd98fcdf5e1f4608be726f6c283f40bd6f43584 /src/mpfr-gmp.h | |
parent | 24cfcf1086269fd2372d4145df694a43cd1ed428 (diff) | |
download | mpfr-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
Diffstat (limited to 'src/mpfr-gmp.h')
-rw-r--r-- | src/mpfr-gmp.h | 14 |
1 files changed, 8 insertions, 6 deletions
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 |