]> git.saurik.com Git - apple/libc.git/blob - gdtoa/FreeBSD/gdtoa-misc.c.patch
Libc-594.9.4.tar.gz
[apple/libc.git] / gdtoa / FreeBSD / gdtoa-misc.c.patch
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 "."). */
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,9 +84,26 @@ 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 - if ( (rv = freelist[k]) !=0) {
74 +#endif /* GDTOA_TSD */
75 + if (k <= Kmax && (rv = freelist[k]) !=0) {
76 freelist[k] = rv->next;
77 }
78 else {
79 @@ -65,7 +113,7 @@ Balloc
80 #else
81 len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
82 /sizeof(double);
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;
86 pmem_next += len;
87 }
88 @@ -75,7 +123,9 @@ Balloc
89 rv->k = k;
90 rv->maxwds = x;
91 }
92 +#ifndef GDTOA_TSD
93 FREE_DTOA_LOCK(0);
94 +#endif /* GDTOA_TSD */
95 rv->sign = rv->wds = 0;
96 return rv;
97 }
98 @@ -89,10 +139,20 @@ Bfree
99 #endif
100 {
101 if (v) {
102 - ACQUIRE_DTOA_LOCK(0);
103 - v->next = freelist[v->k];
104 - freelist[v->k] = v;
105 - FREE_DTOA_LOCK(0);
106 + if (v->k > Kmax)
107 + free((void*)v);
108 + else {
109 +#ifdef GDTOA_TSD
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;
116 +#ifndef GDTOA_TSD
117 + FREE_DTOA_LOCK(0);
118 +#endif /* GDTOA_TSD */
119 + }
120 }
121 }
122