]> git.saurik.com Git - apple/libc.git/blob - gdtoa/FreeBSD/gdtoa-misc.c.patch
Libc-763.12.tar.gz
[apple/libc.git] / gdtoa / FreeBSD / gdtoa-misc.c.patch
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 "."). */
6
7 +#define GDTOA_TSD
8 +#define Omit_Private_Memory
9 +
10 +#ifdef GDTOA_TSD
11 +#include <pthread.h>
12 +#endif /* GDTOA_TSD */
13 #include "gdtoaimp.h"
14
15 +#ifdef 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
22 #ifndef PRIVATE_MEM
23 #define PRIVATE_MEM 2304
24 @@ -40,6 +51,26 @@ THIS SOFTWARE.
25 static double private_mem[PRIVATE_mem], *pmem_next = private_mem;
26 #endif
27
28 +#ifdef GDTOA_TSD
29 +static void
30 +gdtoa_freelist_free(void *x)
31 +{
32 + int i;
33 + Bigint *cur, *next;
34 + Bigint **fl = (Bigint **)x;
35 +
36 + if (!fl) return;
37 + for(i = 0; i < Kmax+1; fl++, i++) {
38 + if (!*fl) continue;
39 + for(cur = *fl; cur; cur = next) {
40 + next = cur->next;
41 + free(cur);
42 + }
43 + }
44 + free(x);
45 + }
46 +#endif /* GDTOA_TSD */
47 +
48 Bigint *
49 Balloc
50 #ifdef KR_headers
51 @@ -53,8 +84,25 @@ Balloc
52 #ifndef Omit_Private_Memory
53 unsigned int len;
54 #endif
55 +#ifdef GDTOA_TSD
56 + Bigint **freelist;
57
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);
63 + }
64 + pthread_mutex_unlock(&gdtoa_tsd_lock);
65 + }
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);
70 + }
71 +#else /* !GDTOA_TSD */
72 ACQUIRE_DTOA_LOCK(0);
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
78 rv->k = k;
79 rv->maxwds = x;
80 }
81 +#ifndef GDTOA_TSD
82 FREE_DTOA_LOCK(0);
83 +#endif /* GDTOA_TSD */
84 rv->sign = rv->wds = 0;
85 return rv;
86 }
87 @@ -98,10 +148,16 @@ Bfree
88 free((void*)v);
89 #endif
90 else {
91 +#ifdef GDTOA_TSD
92 + Bigint **freelist = (Bigint **)pthread_getspecific(gdtoa_tsd_key);
93 +#else /* !GDTOA_TSD */
94 ACQUIRE_DTOA_LOCK(0);
95 +#endif /* !GDTOA_TSD */
96 v->next = freelist[v->k];
97 freelist[v->k] = v;
98 +#ifndef GDTOA_TSD
99 FREE_DTOA_LOCK(0);
100 +#endif /* !GDTOA_TSD */
101 }
102 }
103 }