1 --- gdtoa-misc.c.orig 2010-01-07 22:03:21.000000000 -0800
2 +++ gdtoa-misc.c 2010-01-07 22:25:33.000000000 -0800
3 @@ -29,9 +29,20 @@ THIS SOFTWARE.
4 /* Please send bug reports to David M. Gay (dmg at acm dot org,
5 * with " at " changed at "@" and " dot " changed to "."). */
8 +#define Omit_Private_Memory
12 +#endif /* GDTOA_TSD */
16 +static pthread_key_t gdtoa_tsd_key = (pthread_key_t)-1;
17 +static pthread_mutex_t gdtoa_tsd_lock = PTHREAD_MUTEX_INITIALIZER;
18 +#else /* !GDTOA_TSD */
19 static Bigint *freelist[Kmax+1];
20 +#endif /* GDTOA_TSD */
21 #ifndef Omit_Private_Memory
23 #define PRIVATE_MEM 2304
24 @@ -40,6 +51,26 @@ THIS SOFTWARE.
25 static double private_mem[PRIVATE_mem], *pmem_next = private_mem;
30 +gdtoa_freelist_free(void *x)
34 + Bigint **fl = (Bigint **)x;
37 + for(i = 0; i < Kmax+1; fl++, i++) {
39 + for(cur = *fl; cur; cur = next) {
46 +#endif /* GDTOA_TSD */
51 @@ -53,9 +84,26 @@ Balloc
52 #ifndef Omit_Private_Memory
58 + if (gdtoa_tsd_key == (pthread_key_t)-1) {
59 + pthread_mutex_lock(&gdtoa_tsd_lock);
60 + if (gdtoa_tsd_key == (pthread_key_t)-1) {
61 + gdtoa_tsd_key = __LIBC_PTHREAD_KEY_GDTOA_BIGINT;
62 + pthread_key_init_np(gdtoa_tsd_key, gdtoa_freelist_free);
64 + pthread_mutex_unlock(&gdtoa_tsd_lock);
66 + if ((freelist = (Bigint **)pthread_getspecific(gdtoa_tsd_key)) == NULL) {
67 + freelist = (Bigint **)MALLOC((Kmax+1) * sizeof(Bigint *));
68 + bzero(freelist, (Kmax+1) * sizeof(Bigint *));
69 + pthread_setspecific(gdtoa_tsd_key, freelist);
71 +#else /* !GDTOA_TSD */
73 - if ( (rv = freelist[k]) !=0) {
74 +#endif /* GDTOA_TSD */
75 + if (k <= Kmax && (rv = freelist[k]) !=0) {
76 freelist[k] = rv->next;
79 @@ -65,7 +113,7 @@ Balloc
81 len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
83 - if (pmem_next - private_mem + len <= PRIVATE_mem) {
84 + if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {
85 rv = (Bigint*)pmem_next;
88 @@ -75,7 +123,9 @@ Balloc
94 +#endif /* GDTOA_TSD */
95 rv->sign = rv->wds = 0;
98 @@ -89,10 +139,20 @@ Bfree
102 - ACQUIRE_DTOA_LOCK(0);
103 - v->next = freelist[v->k];
104 - freelist[v->k] = v;
110 + Bigint **freelist = (Bigint **)pthread_getspecific(gdtoa_tsd_key);
111 +#else /* !GDTOA_TSD */
112 + ACQUIRE_DTOA_LOCK(0);
113 +#endif /* GDTOA_TSD */
114 + v->next = freelist[v->k];
115 + freelist[v->k] = v;
118 +#endif /* GDTOA_TSD */