Changeset 1863 in kBuild for trunk/src/kmk/incdep.c
- Timestamp:
- Oct 14, 2008 9:46:23 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/incdep.c
r1862 r1863 145 145 char *file_end; 146 146 147 int is_worker;147 int worker_tid; 148 148 #ifdef PARSE_IN_WORKER 149 149 unsigned int err_line_no; 150 150 const char *err_msg; 151 152 struct dep *dep_start; /* start of the current dep block. */153 struct dep *dep_end; /* end of the current dep block. */154 151 155 152 struct incdep_variable_in_set *recorded_variables_in_set_head; … … 207 204 static struct incdep * volatile incdep_tail_done; 208 205 206 209 207 /* The handles to the worker threads. */ 210 208 #ifdef HAVE_PTHREAD 211 209 static pthread_t incdep_threads[1]; 210 static struct alloccache incdep_dep_caches[1]; 211 static struct alloccache incdep_nameseq_caches[1]; 212 212 213 #elif defined (WINDOWS32) 213 214 static HANDLE incdep_threads[2]; 215 static struct alloccache incdep_dep_caches[2]; 216 static struct alloccache incdep_nameseq_caches[2]; 217 214 218 #elif defined (__OS2__) 215 219 static TID incdep_threads[2]; 220 static struct alloccache incdep_dep_caches[2]; 221 static struct alloccache incdep_nameseq_caches[2]; 216 222 #endif 217 223 static unsigned incdep_num_threads; … … 242 248 243 249 #ifdef __APPLE__ 244 if (cur && cur-> is_worker)250 if (cur && cur->worker_tid != -1) 245 251 { 246 252 ptr = malloc_zone_malloc (incdep_zone, size); … … 258 264 } 259 265 266 #if 0 260 267 /* memset(malloc(sz),'\0',sz) wrapper. */ 261 268 static void * … … 265 272 266 273 #ifdef __APPLE__ 267 if (cur && cur-> is_worker)274 if (cur && cur->worker_tid != -1) 268 275 ptr = malloc_zone_calloc (incdep_zone, size, 1); 269 276 else … … 278 285 return ptr; 279 286 } 287 #endif /* unused */ 280 288 281 289 /* free wrapper */ … … 289 297 } 290 298 299 /* alloc a nameseq structure. */ 300 struct nameseq * 301 incdep_alloc_nameseq (struct incdep *cur) 302 { 303 struct alloccache *cache; 304 if (cur->worker_tid != -1) 305 cache = &incdep_nameseq_caches[cur->worker_tid]; 306 else 307 cache = &nameseq_cache; 308 return alloccache_calloc (cache); 309 } 310 291 311 /* alloc a dep structure. These are allocated in bunches to save time. */ 292 312 struct dep * 293 313 incdep_alloc_dep (struct incdep *cur) 294 314 { 295 if (cur->dep_start != cur->dep_end) 296 return cur->dep_start++; 297 298 cur->dep_start = (struct dep *)incdep_xcalloc (cur, sizeof(struct dep) * 256); 299 cur->dep_end = cur->dep_start + 256; 300 return cur->dep_start++; 301 } 302 315 struct alloccache *cache; 316 if (cur->worker_tid != -1) 317 cache = &incdep_dep_caches[cur->worker_tid]; 318 else 319 cache = &dep_cache; 320 return alloccache_calloc (cache); 321 } 322 323 /* grow a cache. */ 324 static void * 325 incdep_cache_allocator (void *thrd, unsigned int size) 326 { 327 (void)thrd; 328 #ifdef __APPLE__ 329 return malloc_zone_malloc (incdep_zone, size); 330 #else 331 return xmalloc (size); 332 #endif 333 } 303 334 304 335 /* acquires the lock */ … … 472 503 /* A worker thread. */ 473 504 void 474 incdep_worker (void) 475 { 476 #ifdef PARSE_IN_WORKER 477 struct dep *dep_start = NULL; 478 struct dep *dep_end = NULL; 479 #endif 480 505 incdep_worker (int thrd) 506 { 481 507 incdep_lock (); 482 508 … … 500 526 501 527 incdep_unlock (); 502 cur->is_worker = 1; 528 cur->worker_tid = thrd; 529 503 530 incdep_read_file (cur, NILF); 504 505 531 #ifdef PARSE_IN_WORKER 506 cur->dep_start = dep_start;507 cur->dep_end = dep_end;508 509 532 eval_include_dep_file (cur, NILF); 510 511 dep_start = cur->dep_start; 512 cur->dep_start = NULL; 513 dep_end = cur->dep_end; 514 cur->dep_end = NULL; 515 #endif 516 517 cur->is_worker = 0; 533 #endif 534 535 cur->worker_tid = -1; 518 536 incdep_lock (); 519 537 … … 537 555 #ifdef HAVE_PTHREAD 538 556 static void * 539 incdep_worker_pthread (void *ignore) 540 { 541 incdep_worker (); 542 (void)ignore; 557 incdep_worker_pthread (void *thrd) 558 { 559 incdep_worker ((size_t)thrd); 543 560 return NULL; 544 561 } … … 546 563 #elif defined (WINDOWS32) 547 564 static unsigned __stdcall 548 incdep_worker_windows (void *ignore) 549 { 550 incdep_worker (); 551 (void)ignore; 565 incdep_worker_windows (void *thrd) 566 { 567 incdep_worker ((size_t)thrd); 552 568 return 0; 553 569 } … … 555 571 #elif defined (__OS2__) 556 572 static void 557 incdep_worker_os2 (void *ignore) 558 { 559 incdep_worker (); 560 (void)ignore; 573 incdep_worker_os2 (void *thrd) 574 { 575 incdep_worker ((size_t)thrd); 561 576 } 562 577 #endif … … 633 648 for (i = 0; i < incdep_num_threads; i++) 634 649 { 650 alloccache_init (&incdep_dep_caches[i], sizeof(struct dep), "incdep dep", 651 incdep_cache_allocator, (void *)i); 652 alloccache_init (&incdep_nameseq_caches[i], sizeof(struct nameseq), 653 "incdep nameseq", incdep_cache_allocator, (void *)i); 654 635 655 #ifdef HAVE_PTHREAD 636 656 rc = pthread_attr_init (&attr); … … 641 661 if (rc) 642 662 fatal (f, _("pthread_attr_setdetachstate failed: err=%d"), rc); 643 rc = pthread_create 644 incdep_worker_pthread, f);663 rc = pthread_create(&incdep_threads[i], &attr, 664 incdep_worker_pthread, (void *)i); 645 665 if (rc) 646 666 fatal (f, _("pthread_mutex_init failed: err=%d"), rc); … … 650 670 tid = 0; 651 671 hThread = _beginthreadex (NULL, 128*1024, incdep_worker_windows, 652 NULL, 0, &tid);672 (void *)i, 0, &tid); 653 673 if (hThread == 0 || hThread == ~(uintptr_t)0) 654 674 fatal (f, _("_beginthreadex failed: err=%d"), errno); … … 656 676 657 677 #elif defined (__OS2__) 658 tid = _beginthread (incdep_worker_os2, NULL, 128*1024, NULL);678 tid = _beginthread (incdep_worker_os2, NULL, 128*1024, (void *)i); 659 679 if (tid <= 0) 660 680 fatal (f, _("_beginthread failed: err=%d"), errno); … … 691 711 for (i = 0; i < incdep_num_threads; i++) 692 712 { 693 /* later? */ 713 /* more later? */ 714 715 alloccache_join (&dep_cache, &incdep_dep_caches[i]); 716 alloccache_join (&nameseq_cache, &incdep_nameseq_caches[i]); 694 717 } 695 718 incdep_num_threads = 0; … … 803 826 incdep_warn (struct incdep *cur, unsigned int line_no, const char *msg) 804 827 { 805 if ( !cur->is_worker)828 if (cur->worker_tid == -1) 806 829 error (NILF, "%s(%d): %s", cur->name, line_no, msg); 807 830 #ifdef PARSE_IN_WORKER … … 819 842 { 820 843 const char *ret; 821 if ( !cur->is_worker)844 if (cur->worker_tid == -1) 822 845 { 823 846 /* Make sure the string is terminated before we hand it to … … 860 883 { 861 884 assert (!duplicate_value); 862 if ( !cur->is_worker)885 if (cur->worker_tid == -1) 863 886 define_variable_in_set (name, name_length, value, value_length, 864 887 duplicate_value, origin, recursive, set, flocp); … … 898 921 int target_var) 899 922 { 900 if ( !cur->is_worker)923 if (cur->worker_tid == -1) 901 924 do_variable_definition_2 (flocp, name, value, value_length, 0, value, 902 925 origin, flavor, target_var); … … 934 957 const struct floc *flocp) 935 958 { 936 if ( !cur->is_worker)959 if (cur->worker_tid == -1) 937 960 record_files (filenames, pattern, pattern_percent, deps, cmds_started, 938 961 commands, commands_idx, two_colon, flocp); … … 1329 1352 break; 1330 1353 } 1331 filenames = incdep_ xmalloc (curdep, sizeof (struct nameseq));1354 filenames = incdep_alloc_nameseq (curdep); 1332 1355 memset (filenames, 0, sizeof (*filenames)); 1333 1356 filenames->name = incdep_record_strcache (curdep, cur, endp - cur); … … 1469 1492 memcpy (cur->name, name, name_len); 1470 1493 cur->name[name_len] = '\0'; 1471 cur-> is_worker = 0;1494 cur->worker_tid = -1; 1472 1495 #ifdef PARSE_IN_WORKER 1473 1496 cur->err_line_no = 0; 1474 1497 cur->err_msg = NULL; 1475 cur->dep_start = NULL;1476 cur->dep_end = NULL;1477 1498 cur->recorded_variables_in_set_head = NULL; 1478 1499 cur->recorded_variables_in_set_tail = NULL; … … 1491 1512 } 1492 1513 1514 #ifdef ELECTRIC_HEAP 1515 if (1) 1516 #else 1493 1517 if (op == incdep_read_it) 1518 #endif 1494 1519 { 1495 1520 /* work our way thru the files directly */
Note:
See TracChangeset
for help on using the changeset viewer.