Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

133 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. cachep.cxx
  5. Abstract:
  6. This module contains the internal tsunami caching routines
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 16-Jan-1995
  9. --*/
  10. #include "TsunamiP.Hxx"
  11. #pragma hdrstop
  12. // specifies how many characters we will use for hashing string names
  13. # define g_dwFastHashLength (16)
  14. HASH_TYPE
  15. CalculateHashAndLengthOfPathName(
  16. LPCSTR pszPathName,
  17. PULONG pcbLength
  18. )
  19. {
  20. HASH_TYPE hash = 0;
  21. CHAR ch;
  22. DWORD start;
  23. DWORD index;
  24. ASSERT( pszPathName != NULL );
  25. ASSERT( pcbLength != NULL );
  26. *pcbLength = strlen(pszPathName);
  27. //
  28. // hash the last g_dwFastHashLength characters
  29. //
  30. if ( *pcbLength < g_dwFastHashLength ) {
  31. start = 0;
  32. } else {
  33. start = *pcbLength - g_dwFastHashLength;
  34. }
  35. for ( index = start; pszPathName[index] != '\0'; index++ ) {
  36. //
  37. // This is an extremely slimey way of getting upper case.
  38. // Kids, don't try this at home
  39. // -johnson
  40. //
  41. ch = pszPathName[index] & (CHAR)~0x20;
  42. hash <<= 1;
  43. hash ^= ch;
  44. hash <<= 1;
  45. hash += ch;
  46. }
  47. //
  48. // Multiply by length. Murali said so.
  49. //
  50. return( hash * *pcbLength);
  51. } // CalculateHashAndLengthOfPathName
  52. BOOL
  53. DeCache(
  54. PCACHE_OBJECT pCacheObject,
  55. BOOL fLockCacheTable
  56. )
  57. /*++
  58. Description:
  59. This function removes this cache object from any list it may be on.
  60. The cache table lock must be taken if fLockCacheTable is FALSE.
  61. Arguments:
  62. pCacheObject - Object to decache
  63. fLockCacheTable - FALSE if the cache table lock has already been taken
  64. --*/
  65. {
  66. ASSERT( pCacheObject->Signature == CACHE_OBJ_SIGNATURE );
  67. TSUNAMI_TRACE( TRACE_CACHE_DECACHE, pCacheObject );
  68. //
  69. // Already decached if not on any cache lists
  70. //
  71. if ( !RemoveCacheObjFromLists( pCacheObject, fLockCacheTable ) )
  72. {
  73. return TRUE;
  74. }
  75. //
  76. // This undoes the initial reference. The last person to check in this
  77. // cache object will cause it to be deleted after this point.
  78. //
  79. TsDereferenceCacheObj( pCacheObject, fLockCacheTable );
  80. return( TRUE );
  81. }
  82. BOOL
  83. TsDeCacheCachedBlob(
  84. PVOID pBlobPayload
  85. )
  86. /*++
  87. Description:
  88. This function removes a blob payload object from the cache
  89. Arguments:
  90. pCacheObject - Object to decache
  91. --*/
  92. {
  93. return DeCache( (((PBLOB_HEADER)pBlobPayload)-1)->pCache, TRUE );
  94. }