summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib
diff options
context:
space:
mode:
authortegge <tegge@FreeBSD.org>2001-02-09 20:31:48 +0000
committertegge <tegge@FreeBSD.org>2001-02-09 20:31:48 +0000
commit172bac86998f166763796b9b9f4b723694384ad1 (patch)
tree1900efa7a8ffedf113a082b65edf87c48ed81f07 /lib/libc/stdlib
parentfcdd10fefc48869cc1fbebf3946aa47c0bde6293 (diff)
downloadFreeBSD-src-172bac86998f166763796b9b9f4b723694384ad1.zip
FreeBSD-src-172bac86998f166763796b9b9f4b723694384ad1.tar.gz
Backout previous commit. Use of spinlocks was not approved.
PR: 15070
Diffstat (limited to 'lib/libc/stdlib')
-rw-r--r--lib/libc/stdlib/netbsd_strtod.c40
-rw-r--r--lib/libc/stdlib/strtod.c38
2 files changed, 35 insertions, 43 deletions
diff --git a/lib/libc/stdlib/netbsd_strtod.c b/lib/libc/stdlib/netbsd_strtod.c
index ea0dbcd..a402b68 100644
--- a/lib/libc/stdlib/netbsd_strtod.c
+++ b/lib/libc/stdlib/netbsd_strtod.c
@@ -142,7 +142,7 @@ __RCSID("$NetBSD: strtod.c,v 1.26 1998/02/03 18:44:21 perry Exp $");
#include "memory.h"
#endif
#endif
-char *__dtoa __P((double, int, int, int *, int *, char **, char **));
+char *__dtoa __P((double, int, int, int *, int *, char **));
#ifdef MALLOC
#ifdef KR_headers
@@ -384,16 +384,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
@@ -405,13 +395,10 @@ Balloc
int x;
Bigint *rv;
- THREAD_LOCK();
if ((rv = freelist[k]) != NULL) {
freelist[k] = rv->next;
- THREAD_UNLOCK();
}
else {
- THREAD_UNLOCK();
x = 1 << k;
rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(Long));
rv->k = k;
@@ -430,10 +417,8 @@ Bfree
#endif
{
if (v) {
- THREAD_LOCK();
v->next = freelist[v->k];
freelist[v->k] = v;
- THREAD_UNLOCK();
}
}
@@ -1915,11 +1900,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
@@ -1969,6 +1953,15 @@ __dtoa
Bigint *mlo = NULL; /* pacify gcc */
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 */
@@ -2130,8 +2123,11 @@ __dtoa
if (i <= 0)
i = 1;
}
- *resultp = (char *) malloc(i + 1);
- s = s0 = *resultp;
+ j = sizeof(ULong);
+ for(result_k = 0; sizeof(Bigint) - sizeof(ULong) + j <= i;
+ j <<= 1) result_k++;
+ result = Balloc(result_k);
+ s = s0 = (char *)result;
if (ilim >= 0 && ilim <= Quick_max && try_quick) {
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) {
OpenPOWER on IntegriCloud