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.

131 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. File contains the following functions
  6. ActionCache
  7. CacheToA
  8. Revision History:
  9. Amritansh Raghav 6/8/95 Created
  10. --*/
  11. //
  12. // Include files
  13. //
  14. #include "allinc.h"
  15. DWORD
  16. UpdateCache(
  17. DWORD dwCache,
  18. BOOL *fUpdate
  19. )
  20. /*++
  21. Routine Description
  22. Function used to update a cache. It checks to see if the last time
  23. the cache was updated is greater than the time out (A value of 0
  24. for the last time of update means the cache is invalid), calls the
  25. function that loads the cache and then sets the last update time
  26. Locks
  27. Arguments
  28. dwCache This is one of the Cache Ids defined in rtrmgr/defs.h. It
  29. is used to index into the table of locks protecting the caches,
  30. the table of function pointers that holds a pointer to a
  31. function that loads the cache andthe table of last update times
  32. fUpdate Is Set to true if the cache is updated
  33. Return Value
  34. None
  35. --*/
  36. {
  37. DWORD dwResult = NO_ERROR;
  38. LONG dwNeed;
  39. LONG dwSpace;
  40. //
  41. // BUG put in a bounds check here otherwise effects can be disastrous
  42. //
  43. // Trace1(MIB,"Trying to update %s cache", CacheToA(dwCache));
  44. __try
  45. {
  46. ENTER_READER(dwCache);
  47. if((g_LastUpdateTable[dwCache] isnot 0) and
  48. ((GetCurrentTime() - g_LastUpdateTable[dwCache]) < g_TimeoutTable[dwCache]))
  49. {
  50. *fUpdate = FALSE;
  51. dwResult = NO_ERROR;
  52. __leave;
  53. }
  54. READER_TO_WRITER(dwCache);
  55. // Trace0(MIB,"Cache out of date");
  56. dwResult = (*g_LoadFunctionTable[dwCache])();
  57. if(dwResult isnot NO_ERROR)
  58. {
  59. Trace2(ERR,"Error %d loading %s cache",
  60. dwResult,
  61. CacheToA(dwCache));
  62. g_LastUpdateTable[dwCache] = 0;
  63. __leave;
  64. }
  65. g_LastUpdateTable[dwCache] = GetCurrentTime();
  66. dwResult = NO_ERROR;
  67. }
  68. __finally
  69. {
  70. EXIT_LOCK(dwCache);
  71. }
  72. return dwResult; //to keep compiler happy
  73. }
  74. PSZ
  75. CacheToA(
  76. DWORD dwCache
  77. )
  78. {
  79. static PSZ cacheName[] = {"Ip Address Table",
  80. "Ip Forward Table",
  81. "Ip Net To Media table",
  82. "Tcp Table",
  83. "Udp Table",
  84. "Arp Entity Table",
  85. "Illegal Cache Number - ABORT!!!!"};
  86. return( (dwCache >= NUM_CACHE - 1)?
  87. cacheName[NUM_CACHE-1] : cacheName[dwCache]);
  88. }