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.

110 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. File contains the following functions
  6. UpdateCache
  7. Revision History:
  8. Amritansh Raghav 6/8/95 Created
  9. --*/
  10. //
  11. // Include files
  12. //
  13. #include "allinc.h"
  14. PSZ
  15. CacheToA(
  16. DWORD dwCache
  17. );
  18. DWORD
  19. UpdateCache(
  20. DWORD dwCache
  21. )
  22. /*++
  23. Routine Description:
  24. Function used to update a cache. It checks to see if the last time
  25. the cache was updated is greater than the time out (A value of 0
  26. for the last time of update means the cache is invalid), calls the
  27. function that loads the cache and then sets the last update time
  28. Arguments:
  29. dwCache This is one of the Cache Ids defined in
  30. rtrmgr/defs.h. It is used to index into the
  31. table of locks protecting the caches, the table
  32. of function pointers that holds a pointer to a
  33. function that loads the cache andthe table of
  34. last update times
  35. Returns:
  36. NO_ERROR or some error code
  37. --*/
  38. {
  39. DWORD dwResult = NO_ERROR;
  40. LONG dwNeed;
  41. LONG dwSpace;
  42. TRACE1("Trying to update %s Cache",CacheToA(dwCache));
  43. __try
  44. {
  45. EnterWriter(dwCache);
  46. if((g_dwLastUpdateTable[dwCache] isnot 0) and
  47. ((GetCurrentTime() - g_dwLastUpdateTable[dwCache]) < g_dwTimeoutTable[dwCache]))
  48. {
  49. dwResult = NO_ERROR;
  50. __leave;
  51. }
  52. TRACE1("%s Cache out of date",CacheToA(dwCache));
  53. dwResult = (*g_pfnLoadFunctionTable[dwCache])();
  54. if(dwResult isnot NO_ERROR)
  55. {
  56. TRACE1("Unable to load %s Cache\n",CacheToA(dwCache));
  57. g_dwLastUpdateTable[dwCache] = 0;
  58. __leave;
  59. }
  60. TRACE1("%s Cache loaded successfully\n",CacheToA(dwCache));
  61. g_dwLastUpdateTable[dwCache] = GetCurrentTime();
  62. dwResult = NO_ERROR;
  63. }
  64. __finally
  65. {
  66. ReleaseLock(dwCache);
  67. }
  68. return(dwResult);
  69. }
  70. PSZ
  71. CacheToA(
  72. DWORD dwCache
  73. )
  74. {
  75. static PSZ cacheName[] = {
  76. "System ",
  77. "Interfaces",
  78. "Ip Address Table",
  79. "Ip Forward Table",
  80. "Ip Net To Media table",
  81. "Tcp Table",
  82. "Udp Table",
  83. "Arp Entity Table",
  84. "Illegal Cache Number - ABORT!!!!"
  85. };
  86. return((((int) dwCache<0) or (dwCache >= NUM_CACHE - 1))?
  87. cacheName[NUM_CACHE-1] : cacheName[dwCache]);
  88. }