summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.in9
-rw-r--r--exceptions.c6
-rw-r--r--mpfr-impl.h131
-rw-r--r--set_dfl_prec.c7
-rw-r--r--set_rnd.c5
5 files changed, 88 insertions, 70 deletions
diff --git a/configure.in b/configure.in
index 35685784e..8c419c29f 100644
--- a/configure.in
+++ b/configure.in
@@ -76,7 +76,14 @@ AC_ARG_ENABLE(logging,
no) ;;
*) AC_MSG_ERROR([bad value for --enable-logging: yes or no]) ;;
esac])
-
+AC_ARG_ENABLE(thread-safe,
+ [ --enable-thread-safe Build MPFR as thread safe [[default=no]]],
+ [ case $enableval in
+ yes) AC_DEFINE([MPFR_USE_THREAD_SAFE],1,[Build MPFR as thread safe]) ;;
+ no) ;;
+ *) AC_MSG_ERROR([bad value for --enable-thread-safe: yes or no]) ;;
+ esac])
+
test_CFLAGS=${CFLAGS+set}
dnl Same as in gmp acinclude.m4, though currently we're using the normal
diff --git a/exceptions.c b/exceptions.c
index 6e944376c..0947b6612 100644
--- a/exceptions.c
+++ b/exceptions.c
@@ -21,10 +21,10 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
-unsigned int __gmpfr_flags = 0;
+unsigned int MPFR_THREAD_ATTR __gmpfr_flags = 0;
-mp_exp_t __gmpfr_emin = MPFR_EMIN_DEFAULT;
-mp_exp_t __gmpfr_emax = MPFR_EMAX_DEFAULT;
+mp_exp_t MPFR_THREAD_ATTR __gmpfr_emin = MPFR_EMIN_DEFAULT;
+mp_exp_t MPFR_THREAD_ATTR __gmpfr_emax = MPFR_EMAX_DEFAULT;
#undef mpfr_get_emin
diff --git a/mpfr-impl.h b/mpfr-impl.h
index 9c3b2bc92..c62bf8bda 100644
--- a/mpfr-impl.h
+++ b/mpfr-impl.h
@@ -78,65 +78,6 @@ MA 02111-1307, USA. */
/******************************************************
- ***************** Global Variables *******************
- ******************************************************/
-
-#if defined (__cplusplus)
-extern "C" {
-#endif
-
-extern unsigned int __gmpfr_flags;
-extern mp_exp_t __gmpfr_emin;
-extern mp_exp_t __gmpfr_emax;
-extern mp_prec_t __gmpfr_default_fp_bit_precision;
-extern mpfr_rnd_t __gmpfr_default_rounding_mode;
-extern mpfr_cache_t __gmpfr_cache_const_pi;
-extern mpfr_cache_t __gmpfr_cache_const_log2;
-extern mpfr_cache_t __gmpfr_cache_const_euler;
-
-#if defined (__cplusplus)
- }
-#endif
-
-/* Flags of __gmpfr_flags */
-#define MPFR_FLAGS_UNDERFLOW 1
-#define MPFR_FLAGS_OVERFLOW 2
-#define MPFR_FLAGS_NAN 4
-#define MPFR_FLAGS_INEXACT 8
-#define MPFR_FLAGS_ERANGE 16
-#define MPFR_FLAGS_ALL 31
-
-/* Replace some commun functions for direct access to the global vars */
-#define mpfr_get_emin() (__gmpfr_emin + 0)
-#define mpfr_get_emax() (__gmpfr_emax + 0)
-#define mpfr_get_default_rounding_mode() (__gmpfr_default_rounding_mode + 0)
-#define mpfr_get_default_prec() (__gmpfr_default_fp_bit_precision + 0)
-
-#define mpfr_clear_flags() \
- ((void) (__gmpfr_flags = 0))
-#define mpfr_clear_underflow() \
- ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_UNDERFLOW))
-#define mpfr_clear_overflow() \
- ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_OVERFLOW))
-#define mpfr_clear_nanflag() \
- ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_NAN))
-#define mpfr_clear_inexflag() \
- ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_INEXACT))
-#define mpfr_clear_erangeflag() \
- ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_ERANGE))
-#define mpfr_underflow_p() \
- ((int) (__gmpfr_flags & MPFR_FLAGS_UNDERFLOW))
-#define mpfr_overflow_p() \
- ((int) (__gmpfr_flags & MPFR_FLAGS_OVERFLOW))
-#define mpfr_nanflag_p() \
- ((int) (__gmpfr_flags & MPFR_FLAGS_NAN))
-#define mpfr_inexflag_p() \
- ((int) (__gmpfr_flags & MPFR_FLAGS_INEXACT))
-#define mpfr_erangeflag_p() \
- ((int) (__gmpfr_flags & MPFR_FLAGS_ERANGE))
-
-
-/******************************************************
***************** Detection macros *******************
******************************************************/
@@ -213,6 +154,75 @@ mp_limb_t mpfr_sub_nc _MPFR_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t,
/******************************************************
+ ************* Global Internal Variables **************
+ ******************************************************/
+
+#ifdef MPFR_USE_THREAD_SAFE
+# if __MPFR_GNUC(3,3) || __MPFR_ICC(8,1,0)
+# define MPFR_THREAD_ATTR __thread
+# else
+# error "Can't build MPFR as thread safe"
+# endif
+#else
+# define MPFR_THREAD_ATTR
+#endif
+
+#if defined (__cplusplus)
+extern "C" {
+#endif
+
+extern MPFR_THREAD_ATTR unsigned int __gmpfr_flags;
+extern MPFR_THREAD_ATTR mp_exp_t __gmpfr_emin;
+extern MPFR_THREAD_ATTR mp_exp_t __gmpfr_emax;
+extern MPFR_THREAD_ATTR mp_prec_t __gmpfr_default_fp_bit_precision;
+extern MPFR_THREAD_ATTR mpfr_rnd_t __gmpfr_default_rounding_mode;
+extern MPFR_THREAD_ATTR mpfr_cache_t __gmpfr_cache_const_pi;
+extern MPFR_THREAD_ATTR mpfr_cache_t __gmpfr_cache_const_log2;
+extern MPFR_THREAD_ATTR mpfr_cache_t __gmpfr_cache_const_euler;
+
+#if defined (__cplusplus)
+ }
+#endif
+
+/* Flags of __gmpfr_flags */
+#define MPFR_FLAGS_UNDERFLOW 1
+#define MPFR_FLAGS_OVERFLOW 2
+#define MPFR_FLAGS_NAN 4
+#define MPFR_FLAGS_INEXACT 8
+#define MPFR_FLAGS_ERANGE 16
+#define MPFR_FLAGS_ALL 31
+
+/* Replace some commun functions for direct access to the global vars */
+#define mpfr_get_emin() (__gmpfr_emin + 0)
+#define mpfr_get_emax() (__gmpfr_emax + 0)
+#define mpfr_get_default_rounding_mode() (__gmpfr_default_rounding_mode + 0)
+#define mpfr_get_default_prec() (__gmpfr_default_fp_bit_precision + 0)
+
+#define mpfr_clear_flags() \
+ ((void) (__gmpfr_flags = 0))
+#define mpfr_clear_underflow() \
+ ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_UNDERFLOW))
+#define mpfr_clear_overflow() \
+ ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_OVERFLOW))
+#define mpfr_clear_nanflag() \
+ ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_NAN))
+#define mpfr_clear_inexflag() \
+ ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_INEXACT))
+#define mpfr_clear_erangeflag() \
+ ((void) (__gmpfr_flags &= MPFR_FLAGS_ALL ^ MPFR_FLAGS_ERANGE))
+#define mpfr_underflow_p() \
+ ((int) (__gmpfr_flags & MPFR_FLAGS_UNDERFLOW))
+#define mpfr_overflow_p() \
+ ((int) (__gmpfr_flags & MPFR_FLAGS_OVERFLOW))
+#define mpfr_nanflag_p() \
+ ((int) (__gmpfr_flags & MPFR_FLAGS_NAN))
+#define mpfr_inexflag_p() \
+ ((int) (__gmpfr_flags & MPFR_FLAGS_INEXACT))
+#define mpfr_erangeflag_p() \
+ ((int) (__gmpfr_flags & MPFR_FLAGS_ERANGE))
+
+
+/******************************************************
******************** Assertions **********************
******************************************************/
@@ -671,7 +681,8 @@ extern unsigned char *mpfr_stack;
#define mpfr_const_euler(_d,_r) mpfr_cache(_d, __gmpfr_cache_const_euler, _r)
#define MPFR_DECL_INIT_CACHE(_cache,_func) \
- mpfr_cache_t _cache = {{{{0,MPFR_SIGN_POS,0,(mp_limb_t*)0}},0,_func}}
+ mpfr_cache_t MPFR_THREAD_ATTR _cache = \
+ {{{{0,MPFR_SIGN_POS,0,(mp_limb_t*)0}},0,_func}}
diff --git a/set_dfl_prec.c b/set_dfl_prec.c
index 8cf31a102..ca2431308 100644
--- a/set_dfl_prec.c
+++ b/set_dfl_prec.c
@@ -1,6 +1,6 @@
/* mpfr_set_default_prec, mpfr_get_default_prec -- set/get default precision
-Copyright 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
+Copyright 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -22,12 +22,13 @@ MA 02111-1307, USA. */
#include "mpfr-impl.h"
/* default is IEEE double precision, i.e. 53 bits */
-mp_prec_t __gmpfr_default_fp_bit_precision = IEEE_DBL_MANT_DIG;
+mp_prec_t MPFR_THREAD_ATTR __gmpfr_default_fp_bit_precision \
+ = IEEE_DBL_MANT_DIG;
void
mpfr_set_default_prec (mp_prec_t prec)
{
- MPFR_ASSERTN(prec >= MPFR_PREC_MIN && prec <= MPFR_PREC_MAX);
+ MPFR_ASSERTN (prec >= MPFR_PREC_MIN && prec <= MPFR_PREC_MAX);
__gmpfr_default_fp_bit_precision = prec;
}
diff --git a/set_rnd.c b/set_rnd.c
index b2d7a65ea..eafaa30f9 100644
--- a/set_rnd.c
+++ b/set_rnd.c
@@ -1,7 +1,7 @@
/* mpfr_set_default_rounding_mode -- set the default rounding mode
mpfr_get_default_rounding_mode -- get the default rounding mode
-Copyright 1999, 2001, 2004 Free Software Foundation, Inc.
+Copyright 1999, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of the MPFR Library.
@@ -20,10 +20,9 @@ along with the MPFR Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
-
#include "mpfr-impl.h"
-mp_rnd_t __gmpfr_default_rounding_mode = GMP_RNDN;
+mp_rnd_t MPFR_THREAD_ATTR __gmpfr_default_rounding_mode = GMP_RNDN;
void
mpfr_set_default_rounding_mode (mp_rnd_t rnd_mode)