Ignore:
Timestamp:
Oct 13, 2008, 3:50:33 AM (17 years ago)
Author:
bird
Message:

kmk: offload hashing of strcache entries to the includedep thread(s).

File:
1 edited

Legend:

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

    r1845 r1854  
    131131
    132132#ifdef CONFIG_WITH_VALUE_LENGTH
     133/* Hackish globals for passing data to the hash functions.
     134   There isn't really any other way without running the
     135   risk of breaking rehashing. */
    133136static const char *lookup_string;
    134137static unsigned int lookup_string_len;
    135 #endif
     138# ifdef CONFIG_WITH_INCLUDEDEP
     139static unsigned long lookup_string_hash1;
     140static unsigned long lookup_string_hash2;
     141# endif /* CONFIG_WITH_INCLUDEDEP */
     142#endif /* CONFIG_WITH_VALUE_LENGTH */
    136143
    137144static unsigned long
    138145str_hash_1 (const void *key)
    139146{
     147#ifdef CONFIG_WITH_INCLUDEDEP
     148  if ((const char *) key == lookup_string && lookup_string_hash1)
     149    return lookup_string_hash1;
     150#endif
    140151  return_ISTRING_HASH_1 ((const char *) key);
    141152}
     
    144155str_hash_2 (const void *key)
    145156{
     157#ifdef CONFIG_WITH_INCLUDEDEP
     158  if ((const char *) key == lookup_string && lookup_string_hash2)
     159    return lookup_string_hash2;
     160#endif
    146161  return_ISTRING_HASH_2 ((const char *) key);
    147162}
     
    157172     kBuild scenario.  */
    158173
    159   if (x == lookup_string)
     174  if ((const char *) x == lookup_string)
    160175    {
    161176      assert (lookup_string_len == strlen ((const char *)x));
     
    237252}
    238253
     254#ifdef CONFIG_WITH_INCLUDEDEP
     255
     256/* A special variant used by the includedep worker threads, it off loads
     257   the main thread when it adds the strings to the cache later. */
     258const char *
     259strcache_add_prehashed (const char *str, int len, unsigned long hash1,
     260                        unsigned long hash2)
     261{
     262  const char *retstr;
     263
     264  assert (hash1 == str_hash_1 (str));
     265  assert (hash2 == str_hash_2 (str));
     266
     267  lookup_string_hash1 = hash1;
     268  lookup_string_hash2 = hash2;
     269
     270  retstr = add_hash (str, len);
     271
     272  lookup_string_hash1 = 0;
     273  lookup_string_hash2 = 0;
     274
     275  return retstr;
     276}
     277
     278/* Performs the prehashing for use with strcache_add_prehashed(). */
     279void
     280strcache_prehash_str (const char *str, unsigned long *hash1p,
     281                      unsigned long *hash2p)
     282{
     283  *hash1p = str_hash_1 (str);
     284  *hash2p = str_hash_2 (str);
     285}
     286
     287#endif /* CONFIG_WITH_INCLUDEDEP */
     288
    239289int
    240290strcache_setbufsize(int size)
Note: See TracChangeset for help on using the changeset viewer.