VirtualBox

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


Ignore:
Timestamp:
Oct 17, 2008 12:05:27 AM (16 years ago)
Author:
bird
Message:

incdep: use an allocation cache for the records to reduce xmalloc and free calls.

File:
1 edited

Legend:

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

    r1871 r1872  
    9393    struct incdep_variable_in_set *next;
    9494    /* the parameters */
    95     struct strcache2_entry *name_entry; /* dep strcache */
    96     const char *value;              /* xmalloc'ed */
     95    struct strcache2_entry *name_entry;     /* dep strcache - WRONG */
     96    const char *value;                      /* xmalloc'ed */
    9797    unsigned int value_length;
    98     int duplicate_value;            /* 0 */
     98    int duplicate_value;                    /* 0 */
    9999    enum variable_origin origin;
    100100    int recursive;
    101101    struct variable_set *set;
    102     const struct floc *flocp;       /* NILF */
     102    const struct floc *flocp;               /* NILF */
    103103};
    104104
     
    107107    struct incdep_variable_def *next;
    108108    /* the parameters */
    109     const struct floc *flocp;       /* NILF */
    110     struct strcache2_entry *name_entry; /* dep strcache */
    111     char *value;                    /* xmalloc'ed, free it */
     109    const struct floc *flocp;               /* NILF */
     110    struct strcache2_entry *name_entry;     /* dep strcache - WRONG */
     111    char *value;                            /* xmalloc'ed, free it */
    112112    unsigned int value_length;
    113113    enum variable_origin origin;
     
    122122    /* the parameters */
    123123    struct strcache2_entry *filename_entry; /* dep strcache; converted to a nameseq record. */
    124     const char *pattern;            /* NULL */
    125     const char *pattern_percent;    /* NULL */
    126     struct dep *deps;               /* All the names are dep strcache entries. */
    127     unsigned int cmds_started;      /* 0 */
    128     char *commands;                 /* NULL */
    129     unsigned int commands_idx;      /* 0 */
    130     int two_colon;                  /* 0 */
    131     const struct floc *flocp;       /* NILF */
     124    const char *pattern;                    /* NULL */
     125    const char *pattern_percent;            /* NULL */
     126    struct dep *deps;                       /* All the names are dep strcache entries. */
     127    unsigned int cmds_started;              /* 0 */
     128    char *commands;                         /* NULL */
     129    unsigned int commands_idx;              /* 0 */
     130    int two_colon;                          /* 0 */
     131    const struct floc *flocp;               /* NILF */
    132132};
    133133
     
    202202/* The handles to the worker threads. */
    203203#ifdef HAVE_PTHREAD
    204 static pthread_t incdep_threads[1];
    205 static struct alloccache incdep_dep_caches[1];
    206 static struct strcache2 incdep_dep_strcaches[1];
     204# define INCDEP_MAX_THREADS 1
     205static pthread_t incdep_threads[INCDEP_MAX_THREADS];
    207206
    208207#elif defined (WINDOWS32)
    209 static HANDLE incdep_threads[2];
    210 static struct alloccache incdep_dep_caches[2];
    211 static struct strcache2 incdep_dep_strcaches[2];
     208# define INCDEP_MAX_THREADS 2
     209static HANDLE incdep_threads[INCDEP_MAX_THREADS];
    212210
    213211#elif defined (__OS2__)
    214 static TID incdep_threads[2];
    215 static struct alloccache incdep_dep_caches[2];
    216 static struct strcache2 incdep_dep_strcaches[2];
    217 #endif
     212# define INCDEP_MAX_THREADS 2
     213static TID incdep_threads[INCDEP_MAX_THREADS];
     214#endif
     215
     216static struct alloccache incdep_rec_caches[INCDEP_MAX_THREADS];
     217static struct alloccache incdep_dep_caches[INCDEP_MAX_THREADS];
     218static struct strcache2 incdep_dep_strcaches[INCDEP_MAX_THREADS];
    218219static unsigned incdep_num_threads;
    219220
     
    304305}
    305306
     307/* allocate a record. */
     308static void *
     309incdep_alloc_rec (struct incdep *cur)
     310{
     311  return alloccache_alloc (&incdep_rec_caches[cur->worker_tid]);
     312}
     313
     314
    306315/* grow a cache. */
    307316static void *
     
    314323  return xmalloc (size);
    315324#endif
     325}
     326
     327/* term a cache. */
     328static void
     329incdep_cache_deallocator (void *thrd, void *ptr, unsigned int size)
     330{
     331  (void)thrd;
     332  (void)size;
     333  free (ptr);
    316334}
    317335
     
    632650    {
    633651      /* init caches */
     652      unsigned rec_size = sizeof (struct incdep_variable_in_set);
     653      if (rec_size < sizeof (struct incdep_variable_def))
     654        rec_size = sizeof (struct incdep_variable_def);
     655      if (rec_size < sizeof (struct incdep_recorded_files))
     656        rec_size = sizeof (struct incdep_recorded_files);
     657      alloccache_init (&incdep_rec_caches[i], rec_size, "incdep rec",
     658                       incdep_cache_allocator, (void *)(size_t)i);
    634659      alloccache_init (&incdep_dep_caches[i], sizeof(struct dep), "incdep dep",
    635660                       incdep_cache_allocator, (void *)(size_t)i);
     
    706731      /* more later? */
    707732
     733      /* terminate or join up the allocation caches. */
     734      alloccache_term (&incdep_rec_caches[i], incdep_cache_deallocator, (void *)(size_t)i);
    708735      alloccache_join (&dep_cache, &incdep_dep_caches[i]);
    709736      strcache2_term (&incdep_dep_strcaches[i]);
     
    747774    do
    748775      {
    749         void *free_me = rec_vis;
    750776        unsigned int name_length = rec_vis->name_entry->length;
    751777        define_variable_in_set (incdep_flush_strcache_entry (rec_vis->name_entry),
     
    759785                                rec_vis->flocp);
    760786        rec_vis = rec_vis->next;
    761         incdep_xfree (cur, free_me);
    762787      }
    763788    while (rec_vis);
     
    770795    do
    771796      {
    772         void *free_me = rec_vd;
    773797        do_variable_definition_2 (rec_vd->flocp,
    774798                                  incdep_flush_strcache_entry (rec_vd->name_entry),
     
    781805                                  rec_vd->target_var);
    782806        rec_vd = rec_vd->next;
    783         incdep_xfree (cur, free_me);
    784807      }
    785808    while (rec_vd);
     
    792815    do
    793816      {
    794         void *free_me = rec_f;
    795817        struct dep *dep;
    796818        struct nameseq *filenames;
     
    814836
    815837        rec_f = rec_f->next;
    816         incdep_xfree (cur, free_me);
    817838      }
    818839    while (rec_f);
     
    881902  else
    882903    {
    883       struct incdep_variable_in_set *rec = incdep_xmalloc (cur, sizeof (*rec));
     904      struct incdep_variable_in_set *rec =
     905        (struct incdep_variable_in_set *)incdep_alloc_rec (cur);
    884906      rec->name_entry = (struct strcache2_entry *)name;
    885907      rec->value = value;
     
    919941  else
    920942    {
    921       struct incdep_variable_def *rec = incdep_xmalloc (cur, sizeof (*rec));
     943      struct incdep_variable_def *rec =
     944        (struct incdep_variable_def *)incdep_alloc_rec (cur);
    922945      rec->flocp = flocp;
    923946      rec->name_entry = (struct strcache2_entry *)name;
     
    960983  else
    961984    {
    962       struct incdep_recorded_files *rec = incdep_xmalloc (cur, sizeof (*rec));
     985      struct incdep_recorded_files *rec =
     986        (struct incdep_recorded_files *) incdep_alloc_rec (cur);
    963987
    964988      rec->filename_entry = (struct strcache2_entry *)filename;
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