diff options
Diffstat (limited to 'lib/libc/stdlib/strtod.c')
-rw-r--r-- | lib/libc/stdlib/strtod.c | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/libc/stdlib/strtod.c b/lib/libc/stdlib/strtod.c index e70a965..c4fe241 100644 --- a/lib/libc/stdlib/strtod.c +++ b/lib/libc/stdlib/strtod.c @@ -373,16 +373,6 @@ Bigint { static Bigint *freelist[Kmax+1]; - /* - * Make Balloc/Bfree thread-safe in libc for use with - * kernel threads. - */ -#include "libc_private.h" -#include "spinlock.h" -static spinlock_t thread_lock = _SPINLOCK_INITIALIZER; -#define THREAD_LOCK() if (__isthreaded) _SPINLOCK(&thread_lock); -#define THREAD_UNLOCK() if (__isthreaded) _SPINUNLOCK(&thread_lock); - static Bigint * Balloc #ifdef KR_headers @@ -394,12 +384,9 @@ Balloc int x; Bigint *rv; - THREAD_LOCK(); if ( (rv = freelist[k]) ) { freelist[k] = rv->next; - THREAD_UNLOCK(); } else { - THREAD_UNLOCK(); x = 1 << k; rv = (Bigint *)malloc(sizeof(Bigint) + (x-1)*sizeof(long)); rv->k = k; @@ -418,10 +405,8 @@ Bfree #endif { if (v) { - THREAD_LOCK(); v->next = freelist[v->k]; freelist[v->k] = v; - THREAD_UNLOCK(); } } @@ -1856,11 +1841,10 @@ quorem char * __dtoa #ifdef KR_headers - (d, mode, ndigits, decpt, sign, rve, resultp) - double d; int mode, ndigits, *decpt, *sign; char **rve, **resultp; + (d, mode, ndigits, decpt, sign, rve) + double d; int mode, ndigits, *decpt, *sign; char **rve; #else - (double d, int mode, int ndigits, int *decpt, int *sign, char **rve, - char **resultp) + (double d, int mode, int ndigits, int *decpt, int *sign, char **rve) #endif { /* Arguments ndigits, decpt, sign are similar to those @@ -1908,6 +1892,15 @@ __dtoa Bigint *b, *b1, *delta, *mlo, *mhi, *S; double d2, ds, eps; char *s, *s0; + static Bigint *result; + static int result_k; + + if (result) { + result->k = result_k; + result->maxwds = 1 << result_k; + Bfree(result); + result = 0; + } if (word0(d) & Sign_bit) { /* set sign for everything, including 0's and NaNs */ @@ -2066,8 +2059,11 @@ __dtoa if (i <= 0) i = 1; } - *resultp = (char *) malloc(i + 1); - s = s0 = *resultp; + j = sizeof(unsigned long); + for (result_k = 0; sizeof(Bigint) - sizeof(unsigned long) + j < i; + j <<= 1) result_k++; + result = Balloc(result_k); + s = s0 = (char *)result; if (ilim >= 0 && ilim <= Quick_max && try_quick) { |