Changeset 1852 in kBuild for trunk/src/kmk/incdep.c
- Timestamp:
- Oct 13, 2008 12:16:34 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/incdep.c
r1848 r1852 76 76 #endif 77 77 78 #ifdef __APPLE__ 79 # include <malloc/malloc.h> 80 # define PARSE_IN_WORKER 81 #endif 82 78 83 79 84 /******************************************************************************* … … 195 200 /* The handles to the worker threads. */ 196 201 #ifdef HAVE_PTHREAD 197 static pthread_t incdep_threads[ 2];202 static pthread_t incdep_threads[1]; 198 203 #elif defined (WINDOWS32) 199 204 static HANDLE incdep_threads[2]; … … 206 211 static int volatile incdep_terminate; 207 212 213 #ifdef __APPLE__ 214 /* malloc zone for the incdep threads. */ 215 static malloc_zone_t *incdep_zone; 216 #endif 217 208 218 209 219 /******************************************************************************* … … 211 221 *******************************************************************************/ 212 222 static void incdep_flush_it (struct floc *); 213 static void eval_include_dep_file (struct incdep *, struct floc *, int); 223 static void eval_include_dep_file (struct incdep *, struct floc *); 224 225 226 /* xmalloc wrapper. 227 For working around multithreaded performance problems found on Darwin, 228 Linux (glibc), and possibly other systems. */ 229 static void *incdep_xmalloc (struct incdep *cur, size_t size) 230 { 231 void *ptr; 232 233 #ifdef __APPLE__ 234 if (cur && cur->is_worker) 235 { 236 ptr = malloc_zone_malloc (incdep_zone, size); 237 if (!ptr) 238 fatal (NILF, _("virtual memory exhausted")); 239 } 240 else 241 ptr = xmalloc (size); 242 #else 243 ptr = xmalloc (size); 244 #endif 245 246 (void)cur; 247 return ptr; 248 } 249 250 /* memset(malloc(sz),'\0',sz) wrapper. */ 251 static void *incdep_xcalloc (struct incdep *cur, size_t size) 252 { 253 void *ptr; 254 255 #ifdef __APPLE__ 256 if (cur && cur->is_worker) 257 ptr = malloc_zone_calloc (incdep_zone, size, 1); 258 else 259 ptr = calloc (size, 1); 260 #else 261 ptr = calloc (size, 1); 262 #endif 263 if (!ptr) 264 fatal (NILF, _("virtual memory exhausted")); 265 266 (void)cur; 267 return ptr; 268 } 269 270 /* free wrapper */ 271 static void incdep_xfree (struct incdep *cur, void *ptr) 272 { 273 /* free() *must* work for the allocation hacks above because 274 of free_dep_chain. */ 275 free (ptr); 276 (void)cur; 277 } 214 278 215 279 … … 347 411 if (!fstat (fd, &st)) 348 412 { 349 cur->file_base = xmalloc (st.st_size + 1);413 cur->file_base = incdep_xmalloc (cur, st.st_size + 1); 350 414 if (read (fd, cur->file_base, st.st_size) == st.st_size) 351 415 { … … 359 423 360 424 error (f, "%s: read: %s", cur->name, strerror (errno)); 361 free (cur->file_base);425 incdep_xfree (cur, cur->file_base); 362 426 } 363 427 else … … 371 435 /* Free the incdep structure. */ 372 436 static void 373 incdep_free (struct incdep *cur)437 incdep_freeit (struct incdep *cur) 374 438 { 375 439 #ifdef PARSE_IN_WORKER … … 379 443 #endif 380 444 381 free (cur->file_base);445 incdep_xfree (cur, cur->file_base); 382 446 free (cur); 383 447 } … … 408 472 409 473 incdep_unlock (); 474 cur->is_worker = 1; 410 475 incdep_read_file (cur, NILF); 411 476 #ifdef PARSE_IN_WORKER 412 eval_include_dep_file (cur, NILF, 1 /* is_worker */); 413 #endif 477 eval_include_dep_file (cur, NILF); 478 #endif 479 cur->is_worker = 0; 414 480 incdep_lock (); 415 481 … … 475 541 int tid; 476 542 #endif 543 544 /* heap hacks */ 545 546 #ifdef __APPLE__ 547 incdep_zone = malloc_create_zone (0, 0); 548 if (!incdep_zone) 549 incdep_zone = malloc_default_zone (); 550 #endif 551 477 552 478 553 /* create the mutex and two condition variables / event objects. */ … … 615 690 rec_vis->set, 616 691 rec_vis->flocp); 617 free (rec_vis->name);692 incdep_xfree (cur, rec_vis->name); 618 693 rec_vis = rec_vis->next; 619 free (free_me);694 incdep_xfree (cur, free_me); 620 695 } 621 696 while (rec_vis); … … 638 713 rec_vd->flavor, 639 714 rec_vd->target_var); 640 free (rec_vd->name);715 incdep_xfree (cur, rec_vd->name); 641 716 rec_vd = rec_vd->next; 642 free (free_me);717 incdep_xfree (cur, free_me); 643 718 } 644 719 while (rec_vd); … … 663 738 664 739 newname = strcache_add (rec_f->filenames->name); 665 free ((char *)rec_f->filenames->name);740 incdep_xfree (cur, (char *)rec_f->filenames->name); 666 741 rec_f->filenames->name = newname; 667 742 … … 677 752 678 753 rec_f = rec_f->next; 679 free (free_me);754 incdep_xfree (cur, free_me); 680 755 } 681 756 while (rec_f); … … 717 792 /* Duplicate the string. The other recorders knows which arguments 718 793 needs to be added to the string cache later. */ 719 char *newstr = xmalloc (len + 1);794 char *newstr = incdep_xmalloc (cur, len + 1); 720 795 memcpy (newstr, str, len); 721 796 newstr[len] = '\0'; … … 747 822 else 748 823 { 749 struct incdep_variable_in_set *rec = xmalloc (sizeof (*rec));824 struct incdep_variable_in_set *rec = incdep_xmalloc (cur, sizeof (*rec)); 750 825 rec->name = (char *)name; 751 826 rec->name_length = name_length; … … 786 861 else 787 862 { 788 struct incdep_variable_def *rec = xmalloc (sizeof (*rec));863 struct incdep_variable_def *rec = incdep_xmalloc (cur, sizeof (*rec)); 789 864 rec->flocp = flocp; 790 865 rec->name = (char *)name; … … 823 898 else 824 899 { 825 struct incdep_recorded_files *rec = xmalloc (sizeof (*rec));900 struct incdep_recorded_files *rec = incdep_xmalloc (cur, sizeof (*rec)); 826 901 827 902 rec->filenames = filenames; … … 866 941 */ 867 942 static void 868 eval_include_dep_file (struct incdep *curdep, struct floc *f , int is_worker)943 eval_include_dep_file (struct incdep *curdep, struct floc *f) 869 944 { 870 945 unsigned line_no = 1; … … 876 951 if (!cur) 877 952 return; 878 curdep->is_worker = is_worker;879 953 880 954 /* now parse the file. */ … … 983 1057 984 1058 /* make a copy of the value, converting \r\n to \n, and define it. */ 985 value = xmalloc (value_len + 1);1059 value = incdep_xmalloc (curdep, value_len + 1); 986 1060 endp = memchr (value_start, '\r', value_len); 987 1061 if (endp) … … 1142 1216 /* make a copy of the value, converting \r\n to \n, and define it. */ 1143 1217 value_len = value_end - value_start; 1144 value = xmalloc (value_len + 1);1218 value = incdep_xmalloc (curdep, value_len + 1); 1145 1219 if (!multi_line) 1146 1220 memcpy (value, value_start, value_len); … … 1213 1287 break; 1214 1288 } 1215 filenames = xmalloc (sizeof (struct nameseq));1289 filenames = incdep_xmalloc (curdep, sizeof (struct nameseq)); 1216 1290 memset (filenames, 0, sizeof (*filenames)); 1217 1291 filenames->name = incdep_record_strcache (curdep, cur, endp - cur); … … 1253 1327 1254 1328 /* add it to the list. */ 1255 *nextdep = dep = alloc_dep ();1329 *nextdep = dep = incdep_xcalloc (curdep, sizeof (*dep)); 1256 1330 dep->name = incdep_record_strcache (curdep, cur, endp - cur); 1257 1331 dep->includedep = 1; … … 1269 1343 1270 1344 /* free the file data */ 1271 if (is_worker) 1272 { 1273 free (curdep->file_base); 1274 curdep->file_base = curdep->file_end = NULL; 1275 } 1345 incdep_xfree (curdep, curdep->file_base); 1346 curdep->file_base = curdep->file_end = NULL; 1276 1347 } 1277 1348 … … 1296 1367 1297 1368 incdep_read_file (cur, f); 1298 eval_include_dep_file (cur, f , 0);1299 incdep_free (cur);1369 eval_include_dep_file (cur, f); 1370 incdep_freeit (cur); 1300 1371 1301 1372 incdep_lock (); … … 1324 1395 incdep_flush_recorded_instructions (cur); 1325 1396 #else 1326 eval_include_dep_file (cur, f , 0);1327 #endif 1328 incdep_free (cur);1397 eval_include_dep_file (cur, f); 1398 #endif 1399 incdep_freeit (cur); 1329 1400 cur = next; 1330 1401 } … … 1352 1423 while ((name = find_next_token (&names_iterator, &name_len)) != 0) 1353 1424 { 1354 cur = xmalloc (sizeof (*cur) + name_len); 1425 cur = xmalloc (sizeof (*cur) + name_len); /* not incdep_xmalloc here */ 1355 1426 cur->file_base = cur->file_end = NULL; 1356 1427 memcpy (cur->name, name, name_len); … … 1385 1456 struct incdep *next = cur->next; 1386 1457 incdep_read_file (cur, f); 1387 eval_include_dep_file (cur, f, 0); /* eats cur */ 1458 eval_include_dep_file (cur, f); 1459 incdep_freeit (cur); 1388 1460 cur = next; 1389 1461 }
Note:
See TracChangeset
for help on using the changeset viewer.