1 --- gdtoa-misc.c.orig 2010-01-12 10:59:42.000000000 -0800
2 +++ gdtoa-misc.c 2010-01-12 12:08:17.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,8 +84,25 @@ 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 +#endif /* GDTOA_TSD */
74 /* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */
75 /* but this case seems very unlikely. */
76 if (k <= Kmax && (rv = freelist[k]) !=0) {
77 @@ -77,7 +125,9 @@ Balloc
83 +#endif /* GDTOA_TSD */
84 rv->sign = rv->wds = 0;
87 @@ -98,10 +148,16 @@ Bfree
92 + Bigint **freelist = (Bigint **)pthread_getspecific(gdtoa_tsd_key);
93 +#else /* !GDTOA_TSD */
95 +#endif /* !GDTOA_TSD */
96 v->next = freelist[v->k];
100 +#endif /* !GDTOA_TSD */