VirtualBox

Changeset 1863 in kBuild for trunk/src/kmk/incdep.c


Ignore:
Timestamp:
Oct 14, 2008 9:46:23 AM (16 years ago)
Author:
bird
Message:

kmk: Allocation caches for nameseq, dep and idep. next: variable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/incdep.c

    r1862 r1863  
    145145  char *file_end;
    146146
    147   int is_worker;
     147  int worker_tid;
    148148#ifdef PARSE_IN_WORKER
    149149  unsigned int err_line_no;
    150150  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. */
    154151
    155152  struct incdep_variable_in_set *recorded_variables_in_set_head;
     
    207204static struct incdep * volatile incdep_tail_done;
    208205
     206
    209207/* The handles to the worker threads. */
    210208#ifdef HAVE_PTHREAD
    211209static pthread_t incdep_threads[1];
     210static struct alloccache incdep_dep_caches[1];
     211static struct alloccache incdep_nameseq_caches[1];
     212
    212213#elif defined (WINDOWS32)
    213214static HANDLE incdep_threads[2];
     215static struct alloccache incdep_dep_caches[2];
     216static struct alloccache incdep_nameseq_caches[2];
     217
    214218#elif defined (__OS2__)
    215219static TID incdep_threads[2];
     220static struct alloccache incdep_dep_caches[2];
     221static struct alloccache incdep_nameseq_caches[2];
    216222#endif
    217223static unsigned incdep_num_threads;
     
    242248
    243249#ifdef __APPLE__
    244   if (cur && cur->is_worker)
     250  if (cur && cur->worker_tid != -1)
    245251    {
    246252      ptr = malloc_zone_malloc (incdep_zone, size);
     
    258264}
    259265
     266#if 0
    260267/* memset(malloc(sz),'\0',sz) wrapper. */
    261268static void *
     
    265272
    266273#ifdef __APPLE__
    267   if (cur && cur->is_worker)
     274  if (cur && cur->worker_tid != -1)
    268275    ptr = malloc_zone_calloc (incdep_zone, size, 1);
    269276  else
     
    278285  return ptr;
    279286}
     287#endif /* unused */
    280288
    281289/* free wrapper */
     
    289297}
    290298
     299/* alloc a nameseq structure.  */
     300struct nameseq *
     301incdep_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
    291311/* alloc a dep structure. These are allocated in bunches to save time. */
    292312struct dep *
    293313incdep_alloc_dep (struct incdep *cur)
    294314{
    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. */
     324static void *
     325incdep_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}
    303334
    304335/* acquires the lock */
     
    472503/* A worker thread. */
    473504void
    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 
     505incdep_worker (int thrd)
     506{
    481507  incdep_lock ();
    482508
     
    500526
    501527      incdep_unlock ();
    502       cur->is_worker = 1;
     528      cur->worker_tid = thrd;
     529
    503530      incdep_read_file (cur, NILF);
    504 
    505531#ifdef PARSE_IN_WORKER
    506       cur->dep_start = dep_start;
    507       cur->dep_end = dep_end;
    508 
    509532      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;
    518536      incdep_lock ();
    519537
     
    537555#ifdef HAVE_PTHREAD
    538556static void *
    539 incdep_worker_pthread (void *ignore)
    540 {
    541   incdep_worker ();
    542   (void)ignore;
     557incdep_worker_pthread (void *thrd)
     558{
     559  incdep_worker ((size_t)thrd);
    543560  return NULL;
    544561}
     
    546563#elif defined (WINDOWS32)
    547564static unsigned __stdcall
    548 incdep_worker_windows (void *ignore)
    549 {
    550   incdep_worker ();
    551   (void)ignore;
     565incdep_worker_windows (void *thrd)
     566{
     567  incdep_worker ((size_t)thrd);
    552568  return 0;
    553569}
     
    555571#elif defined (__OS2__)
    556572static void
    557 incdep_worker_os2 (void *ignore)
    558 {
    559   incdep_worker ();
    560   (void)ignore;
     573incdep_worker_os2 (void *thrd)
     574{
     575  incdep_worker ((size_t)thrd);
    561576}
    562577#endif
     
    633648  for (i = 0; i < incdep_num_threads; i++)
    634649    {
     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
    635655#ifdef HAVE_PTHREAD
    636656      rc = pthread_attr_init (&attr);
     
    641661      if (rc)
    642662        fatal (f, _("pthread_attr_setdetachstate failed: err=%d"), rc);
    643       rc = pthread_create (&incdep_threads[i], &attr,
    644                            incdep_worker_pthread, f);
     663      rc = pthread_create(&incdep_threads[i], &attr,
     664                           incdep_worker_pthread, (void *)i);
    645665      if (rc)
    646666        fatal (f, _("pthread_mutex_init failed: err=%d"), rc);
     
    650670      tid = 0;
    651671      hThread = _beginthreadex (NULL, 128*1024, incdep_worker_windows,
    652                                 NULL, 0, &tid);
     672                                (void *)i, 0, &tid);
    653673      if (hThread == 0 || hThread == ~(uintptr_t)0)
    654674        fatal (f, _("_beginthreadex failed: err=%d"), errno);
     
    656676
    657677#elif defined (__OS2__)
    658       tid = _beginthread (incdep_worker_os2, NULL, 128*1024, NULL);
     678      tid = _beginthread (incdep_worker_os2, NULL, 128*1024, (void *)i);
    659679      if (tid <= 0)
    660680        fatal (f, _("_beginthread failed: err=%d"), errno);
     
    691711  for (i = 0; i < incdep_num_threads; i++)
    692712    {
    693       /* later? */
     713      /* more later? */
     714
     715      alloccache_join (&dep_cache, &incdep_dep_caches[i]);
     716      alloccache_join (&nameseq_cache, &incdep_nameseq_caches[i]);
    694717    }
    695718  incdep_num_threads = 0;
     
    803826incdep_warn (struct incdep *cur, unsigned int line_no, const char *msg)
    804827{
    805   if (!cur->is_worker)
     828  if (cur->worker_tid == -1)
    806829    error (NILF, "%s(%d): %s", cur->name, line_no, msg);
    807830#ifdef PARSE_IN_WORKER
     
    819842{
    820843  const char *ret;
    821   if (!cur->is_worker)
     844  if (cur->worker_tid == -1)
    822845    {
    823846      /* Make sure the string is terminated before we hand it to
     
    860883{
    861884  assert (!duplicate_value);
    862   if (!cur->is_worker)
     885  if (cur->worker_tid == -1)
    863886    define_variable_in_set (name, name_length, value, value_length,
    864887                            duplicate_value, origin, recursive, set, flocp);
     
    898921                            int target_var)
    899922{
    900   if (!cur->is_worker)
     923  if (cur->worker_tid == -1)
    901924    do_variable_definition_2 (flocp, name, value, value_length, 0, value,
    902925                              origin, flavor, target_var);
     
    934957                     const struct floc *flocp)
    935958{
    936   if (!cur->is_worker)
     959  if (cur->worker_tid == -1)
    937960    record_files (filenames, pattern, pattern_percent, deps, cmds_started,
    938961                  commands, commands_idx, two_colon, flocp);
     
    13291352                  break;
    13301353                }
    1331               filenames = incdep_xmalloc (curdep, sizeof (struct nameseq));
     1354              filenames = incdep_alloc_nameseq (curdep);
    13321355              memset (filenames, 0, sizeof (*filenames));
    13331356              filenames->name = incdep_record_strcache (curdep, cur, endp - cur);
     
    14691492       memcpy (cur->name, name, name_len);
    14701493       cur->name[name_len] = '\0';
    1471        cur->is_worker = 0;
     1494       cur->worker_tid = -1;
    14721495#ifdef PARSE_IN_WORKER
    14731496       cur->err_line_no = 0;
    14741497       cur->err_msg = NULL;
    1475        cur->dep_start = NULL;
    1476        cur->dep_end = NULL;
    14771498       cur->recorded_variables_in_set_head = NULL;
    14781499       cur->recorded_variables_in_set_tail = NULL;
     
    14911512    }
    14921513
     1514#ifdef ELECTRIC_HEAP
     1515  if (1)
     1516#else
    14931517  if (op == incdep_read_it)
     1518#endif
    14941519    {
    14951520      /* work our way thru the files directly */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette