summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-10-24 13:03:53 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-10-24 13:03:53 +0000
commit70af868da2b1d573df3b759a68da2117c485fa11 (patch)
tree6cccd6ab0747a5942b9a6a3cc00dd536011c2e08
parent56de65bac890ab1b838f8f87837595b4a1021826 (diff)
downloadmpfr-70af868da2b1d573df3b759a68da2117c485fa11.tar.gz
[src] Support build as thread-safe DLL on Windows: clean-up.
* Increased the use of macros to avoid some code duplication (with risks of typos) and to prevent the problems related to thread-safe DLL from appearing in the .c files. * The prototypes of the functions to access the address of a TLS variable are now defined. Otherwise one gets warnings: https://sympa.inria.fr/sympa/arc/mpfr/2016-10/msg00004.html (merged changeset r10916 from the trunk, with conflict resolved by replacing mpfr_flags_t with unsigned int) git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/3.1@10917 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/const_catalan.c10
-rw-r--r--src/const_euler.c10
-rw-r--r--src/const_log2.c18
-rw-r--r--src/const_pi.c18
-rw-r--r--src/exceptions.c13
-rw-r--r--src/mpfr-impl.h39
-rw-r--r--src/set_dfl_prec.c11
-rw-r--r--src/set_rnd.c10
8 files changed, 39 insertions, 90 deletions
diff --git a/src/const_catalan.c b/src/const_catalan.c
index 41b6bd97d..d7daa36e1 100644
--- a/src/const_catalan.c
+++ b/src/const_catalan.c
@@ -24,15 +24,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#include "mpfr-impl.h"
/* Declare the cache */
-MPFR_DECL_INIT_CACHE(__gmpfr_cache_const_catalan, mpfr_const_catalan_internal);
-
-#ifdef MPFR_WIN_THREAD_SAFE_DLL
-mpfr_cache_t *
-__gmpfr_cache_const_catalan_f()
-{
- return &__gmpfr_cache_const_catalan;
-}
-#endif
+MPFR_DECL_INIT_CACHE (__gmpfr_cache_const_catalan, mpfr_const_catalan_internal)
/* Set User Interface */
#undef mpfr_const_catalan
diff --git a/src/const_euler.c b/src/const_euler.c
index e00dda53d..261557e81 100644
--- a/src/const_euler.c
+++ b/src/const_euler.c
@@ -24,15 +24,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#include "mpfr-impl.h"
/* Declare the cache */
-MPFR_DECL_INIT_CACHE(__gmpfr_cache_const_euler, mpfr_const_euler_internal);
-
-#ifdef MPFR_WIN_THREAD_SAFE_DLL
-mpfr_cache_t *
-__gmpfr_cache_const_euler_f()
-{
- return &__gmpfr_cache_const_euler;
-}
-#endif
+MPFR_DECL_INIT_CACHE (__gmpfr_cache_const_euler, mpfr_const_euler_internal)
/* Set User Interface */
#undef mpfr_const_euler
diff --git a/src/const_log2.c b/src/const_log2.c
index 8496d2d58..255e8b3dc 100644
--- a/src/const_log2.c
+++ b/src/const_log2.c
@@ -25,21 +25,11 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
/* Declare the cache */
#ifndef MPFR_USE_LOGGING
-MPFR_DECL_INIT_CACHE(__gmpfr_cache_const_log2, mpfr_const_log2_internal);
+MPFR_DECL_INIT_CACHE (__gmpfr_cache_const_log2, mpfr_const_log2_internal)
#else
-MPFR_DECL_INIT_CACHE(__gmpfr_normal_log2, mpfr_const_log2_internal);
-MPFR_DECL_INIT_CACHE(__gmpfr_logging_log2, mpfr_const_log2_internal);
-MPFR_THREAD_ATTR mpfr_cache_ptr __gmpfr_cache_const_log2 = __gmpfr_normal_log2;
-#endif
-
-#ifdef MPFR_WIN_THREAD_SAFE_DLL
-# ifndef MPFR_USE_LOGGING
-mpfr_cache_t * __gmpfr_cache_const_log2_f() { return &__gmpfr_cache_const_log2; }
-# else
-mpfr_cache_t * __gmpfr_normal_log2_f() { return &__gmpfr_normal_log2; }
-mpfr_cache_t * __gmpfr_logging_log2_f() { return &__gmpfr_logging_log2; }
-mpfr_cache_ptr * __gmpfr_cache_const_log2_f() { return &__gmpfr_cache_const_log2; }
-# endif
+MPFR_DECL_INIT_CACHE (__gmpfr_normal_log2, mpfr_const_log2_internal)
+MPFR_DECL_INIT_CACHE (__gmpfr_logging_log2, mpfr_const_log2_internal)
+MPFR_THREAD_VAR (mpfr_cache_ptr, __gmpfr_cache_const_log2, __gmpfr_normal_log2)
#endif
/* Set User interface */
diff --git a/src/const_pi.c b/src/const_pi.c
index 7c555c9ee..9f7e50cc0 100644
--- a/src/const_pi.c
+++ b/src/const_pi.c
@@ -24,21 +24,11 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
/* Declare the cache */
#ifndef MPFR_USE_LOGGING
-MPFR_DECL_INIT_CACHE(__gmpfr_cache_const_pi, mpfr_const_pi_internal);
+MPFR_DECL_INIT_CACHE (__gmpfr_cache_const_pi, mpfr_const_pi_internal)
#else
-MPFR_DECL_INIT_CACHE(__gmpfr_normal_pi, mpfr_const_pi_internal);
-MPFR_DECL_INIT_CACHE(__gmpfr_logging_pi, mpfr_const_pi_internal);
-MPFR_THREAD_ATTR mpfr_cache_ptr __gmpfr_cache_const_pi = __gmpfr_normal_pi;
-#endif
-
-#ifdef MPFR_WIN_THREAD_SAFE_DLL
-# ifndef MPFR_USE_LOGGING
-mpfr_cache_t * __gmpfr_cache_const_pi_f() { return &__gmpfr_cache_const_pi; }
-# else
-mpfr_cache_t * __gmpfr_normal_pi_f() { return &__gmpfr_normal_pi; }
-mpfr_cache_t * __gmpfr_logging_pi_f() { return &__gmpfr_logging_pi; }
-mpfr_cache_ptr * __gmpfr_cache_const_pi_f() { return &__gmpfr_cache_const_pi; }
-# endif
+MPFR_DECL_INIT_CACHE (__gmpfr_normal_pi, mpfr_const_pi_internal)
+MPFR_DECL_INIT_CACHE (__gmpfr_logging_pi, mpfr_const_pi_internal)
+MPFR_THREAD_VAR (mpfr_cache_ptr, __gmpfr_cache_const_pi, __gmpfr_normal_pi)
#endif
/* Set User Interface */
diff --git a/src/exceptions.c b/src/exceptions.c
index ad8beb2c4..b7eb3199c 100644
--- a/src/exceptions.c
+++ b/src/exceptions.c
@@ -22,16 +22,9 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#include "mpfr-impl.h"
-MPFR_THREAD_ATTR unsigned int __gmpfr_flags = 0;
-
-MPFR_THREAD_ATTR mpfr_exp_t __gmpfr_emin = MPFR_EMIN_DEFAULT;
-MPFR_THREAD_ATTR mpfr_exp_t __gmpfr_emax = MPFR_EMAX_DEFAULT;
-
-#ifdef MPFR_WIN_THREAD_SAFE_DLL
-unsigned int * __gmpfr_flags_f() { return &__gmpfr_flags; }
-mpfr_exp_t * __gmpfr_emin_f() { return &__gmpfr_emin; }
-mpfr_exp_t * __gmpfr_emax_f() { return &__gmpfr_emax; }
-#endif
+MPFR_THREAD_VAR (unsigned int, __gmpfr_flags, 0)
+MPFR_THREAD_VAR (mpfr_exp_t, __gmpfr_emin, MPFR_EMIN_DEFAULT)
+MPFR_THREAD_VAR (mpfr_exp_t, __gmpfr_emax, MPFR_EMAX_DEFAULT)
#undef mpfr_get_emin
diff --git a/src/mpfr-impl.h b/src/mpfr-impl.h
index e9c0db62f..4c5ed6666 100644
--- a/src/mpfr-impl.h
+++ b/src/mpfr-impl.h
@@ -253,6 +253,7 @@ typedef struct __gmpfr_cache_s *mpfr_cache_ptr;
#endif
#if defined(__MPFR_WITHIN_MPFR) || !defined(MPFR_WIN_THREAD_SAFE_DLL)
+# define MPFR_MAKE_VARFCT(T,N)
extern MPFR_THREAD_ATTR unsigned int __gmpfr_flags;
extern MPFR_THREAD_ATTR mpfr_exp_t __gmpfr_emin;
extern MPFR_THREAD_ATTR mpfr_exp_t __gmpfr_emax;
@@ -278,23 +279,24 @@ extern MPFR_THREAD_ATTR mpfr_cache_ptr __gmpfr_cache_const_log2;
#endif
#ifdef MPFR_WIN_THREAD_SAFE_DLL
-__MPFR_DECLSPEC unsigned int * __gmpfr_flags_f();
-__MPFR_DECLSPEC mpfr_exp_t * __gmpfr_emin_f();
-__MPFR_DECLSPEC mpfr_exp_t * __gmpfr_emax_f();
-__MPFR_DECLSPEC mpfr_prec_t * __gmpfr_default_fp_bit_precision_f();
-__MPFR_DECLSPEC mpfr_rnd_t * __gmpfr_default_rounding_mode_f();
-__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_cache_const_euler_f();
-__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_cache_const_catalan_f();
+# define MPFR_MAKE_VARFCT(T,N) T * N ## _f (void) { return &N; }
+__MPFR_DECLSPEC unsigned int * __gmpfr_flags_f (void);
+__MPFR_DECLSPEC mpfr_exp_t * __gmpfr_emin_f (void);
+__MPFR_DECLSPEC mpfr_exp_t * __gmpfr_emax_f (void);
+__MPFR_DECLSPEC mpfr_prec_t * __gmpfr_default_fp_bit_precision_f (void);
+__MPFR_DECLSPEC mpfr_rnd_t * __gmpfr_default_rounding_mode_f (void);
+__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_cache_const_euler_f (void);
+__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_cache_const_catalan_f (void);
# ifndef MPFR_USE_LOGGING
-__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_cache_const_pi_f();
-__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_cache_const_log2_f();
+__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_cache_const_pi_f (void);
+__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_cache_const_log2_f (void);
# else
-__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_normal_pi_f();
-__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_normal_log2_f();
-__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_logging_pi_f();
-__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_logging_log2_f();
-__MPFR_DECLSPEC mpfr_cache_ptr * __gmpfr_cache_const_pi_f();
-__MPFR_DECLSPEC mpfr_cache_ptr * __gmpfr_cache_const_log2_f();
+__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_normal_pi_f (void);
+__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_normal_log2_f (void);
+__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_logging_pi_f (void);
+__MPFR_DECLSPEC mpfr_cache_t * __gmpfr_logging_log2_f (void);
+__MPFR_DECLSPEC mpfr_cache_ptr * __gmpfr_cache_const_pi_f (void);
+__MPFR_DECLSPEC mpfr_cache_ptr * __gmpfr_cache_const_log2_f (void);
# endif
# ifndef __MPFR_WITHIN_MPFR
# define __gmpfr_flags (*__gmpfr_flags_f())
@@ -317,6 +319,10 @@ __MPFR_DECLSPEC mpfr_cache_ptr * __gmpfr_cache_const_log2_f();
# endif
#endif
+# define MPFR_THREAD_VAR(T,N,V) \
+ MPFR_THREAD_ATTR T N = V; \
+ MPFR_MAKE_VARFCT (T,N)
+
#define BASE_MAX 62
__MPFR_DECLSPEC extern const __mpfr_struct __gmpfr_l2b[BASE_MAX-1][2];
@@ -1045,7 +1051,8 @@ extern unsigned char *mpfr_stack;
#define MPFR_DECL_INIT_CACHE(_cache,_func) \
MPFR_THREAD_ATTR mpfr_cache_t _cache = \
- {{{{0,MPFR_SIGN_POS,0,(mp_limb_t*)0}},0,_func}}
+ {{{{0,MPFR_SIGN_POS,0,(mp_limb_t*)0}},0,_func}}; \
+ MPFR_MAKE_VARFCT (mpfr_cache_t,_cache)
diff --git a/src/set_dfl_prec.c b/src/set_dfl_prec.c
index 96464c459..df44a69b9 100644
--- a/src/set_dfl_prec.c
+++ b/src/set_dfl_prec.c
@@ -23,15 +23,8 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#include "mpfr-impl.h"
/* default is IEEE double precision, i.e. 53 bits */
-MPFR_THREAD_ATTR mpfr_prec_t __gmpfr_default_fp_bit_precision \
- = IEEE_DBL_MANT_DIG;
-
-#ifdef MPFR_WIN_THREAD_SAFE_DLL
-mpfr_prec_t * __gmpfr_default_fp_bit_precision_f()
-{
- return &__gmpfr_default_fp_bit_precision;
-}
-#endif
+MPFR_THREAD_VAR (mpfr_prec_t, __gmpfr_default_fp_bit_precision,
+ IEEE_DBL_MANT_DIG)
void
mpfr_set_default_prec (mpfr_prec_t prec)
diff --git a/src/set_rnd.c b/src/set_rnd.c
index 10fc23231..bb96930da 100644
--- a/src/set_rnd.c
+++ b/src/set_rnd.c
@@ -23,15 +23,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#include "mpfr-impl.h"
-MPFR_THREAD_ATTR mpfr_rnd_t __gmpfr_default_rounding_mode = MPFR_RNDN;
-
-#ifdef MPFR_WIN_THREAD_SAFE_DLL
-mpfr_rnd_t *
-__gmpfr_default_rounding_mode_f()
-{
- return &__gmpfr_default_rounding_mode;
-}
-#endif
+MPFR_THREAD_VAR (mpfr_rnd_t, __gmpfr_default_rounding_mode, MPFR_RNDN)
void
mpfr_set_default_rounding_mode (mpfr_rnd_t rnd_mode)