Windows NT 4.0 source code leak
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.

220 lines
4.7 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. scavthrd.c
  5. Abstract:
  6. This module implements the redirector's scavenger thread. This thread
  7. is responsible for closing out dormant connections and other non time
  8. critical operations.
  9. Author:
  10. Larry Osterman (LarryO) 13-Aug-1990
  11. Revision History:
  12. 13-Aug-1990 LarryO
  13. Created
  14. --*/
  15. #include "precomp.h"
  16. #pragma hdrstop
  17. //
  18. // This counter is used to control kicking the scavenger thread.
  19. //
  20. LONG TimerCounter = {0};
  21. WORK_QUEUE_ITEM CancelWorkItem = {0};
  22. WORK_QUEUE_ITEM TimerWorkItem = {0};
  23. #ifdef ALLOC_PRAGMA
  24. #pragma alloc_text(PAGE,RdrTimer)
  25. #endif
  26. VOID
  27. RdrTimer (
  28. IN PVOID Context
  29. )
  30. /*++
  31. Routine Description:
  32. This function implements the NT redirector's scavenger thread. It
  33. performs all idle time operations such as closing out dormant connections
  34. etc.
  35. Arguments:
  36. IN PFS_DEVICE_OBJECT DeviceObject - Supplies the device object associated
  37. with this request.
  38. Return Value:
  39. None.
  40. --*/
  41. {
  42. PAGED_CODE();
  43. dprintf(DPRT_SCAVTHRD, ("RdrTimer\n"));
  44. //
  45. // Get rid of aged server entries
  46. //
  47. RdrScavengeServerEntries();
  48. //
  49. // First scan for dormant connections to remove.
  50. //
  51. RdrScanForDormantConnections(0, NULL);
  52. //RdrScanForDormantSecurityEntries();
  53. //
  54. // Now check the list of open outstanding files and remove any that are
  55. // "too old" from the cache.
  56. //
  57. RdrPurgeDormantCachedFiles();
  58. //
  59. // Request updated throughput, delay and reliability information from the
  60. // transport for each connection.
  61. //
  62. RdrEvaluateTimeouts();
  63. //
  64. // Now "PING" remote servers for longterm requests that have been active
  65. // for more than the timeout period.
  66. //
  67. RdrPingLongtermOperations();
  68. //
  69. // Allow the timer work item to be requeued. Note that we do not set the timer
  70. // counter to its initial value here. This may mean that we'll be restarted in
  71. // less than the specified interval. But that can only happen when it's taken
  72. // this thread some time to run, so it's OK. We used to clear the Flink on entry
  73. // to this routine, but that caused the routine to run pretty much continuously
  74. // when netcon was running because the thread kept getting stuck behind netcon
  75. // activity.
  76. //
  77. TimerWorkItem.List.Flink = NULL;
  78. Context;
  79. }
  80. VOID
  81. RdrIdleTimer (
  82. IN PDEVICE_OBJECT DeviceObject,
  83. IN PVOID Context
  84. )
  85. /*++
  86. Routine Description:
  87. This routine implements the NT redirector's scavenger thread timer.
  88. It basically waits for the timer granularity and kicks the scavenger
  89. thread.
  90. Arguments:
  91. IN PDEVICE_OBJECT DeviceObject - Supplies the device object for the timer
  92. IN PVOID Context - Ignored in this routine.
  93. Return Value:
  94. None.
  95. --*/
  96. {
  97. //
  98. // Bump the current time counter.
  99. //
  100. RdrCurrentTime++;
  101. //
  102. // Check to see if it's time to cancel outstanding requests or
  103. // for the idle timer to run.
  104. //
  105. if (--TimerCounter == 0) {
  106. TimerCounter = SCAVENGER_TIMER_GRANULARITY;
  107. //
  108. // If there are any outstanding commands, check to see if they've
  109. // timed out.
  110. //
  111. if (RdrStatistics.CurrentCommands != 0) {
  112. //
  113. // Please note that we use the kernel work queue routines directly for
  114. // this instead of going through the normal redirector work queue
  115. // routines. We do this because the redirector work queue routines will
  116. // only allow a limited number of requests through to the worker threads,
  117. // and it is critical that this request run (if it didn't, there could be
  118. // a worker thread that was blocked waiting on the request to be canceled
  119. // could never happen because the cancelation routine was behind it on
  120. // the work queue.
  121. //
  122. if (CancelWorkItem.List.Flink == NULL) {
  123. ExQueueWorkItem(&CancelWorkItem, CriticalWorkQueue);
  124. }
  125. }
  126. //
  127. // Queue up a scavenger request to a generic worker thread.
  128. //
  129. if (TimerWorkItem.List.Flink == NULL) {
  130. RdrQueueWorkItem(&TimerWorkItem, DelayedWorkQueue);
  131. }
  132. }
  133. return;
  134. DeviceObject;Context;
  135. }
  136. VOID
  137. RdrInitializeTimerPackage (
  138. VOID
  139. )
  140. {
  141. ExInitializeWorkItem( &TimerWorkItem, RdrTimer, NULL );
  142. ExInitializeWorkItem( &CancelWorkItem, RdrCancelOutstandingRequests, NULL );
  143. //
  144. // Set the timer up for the idle timer.
  145. //
  146. TimerCounter = SCAVENGER_TIMER_GRANULARITY;
  147. IoInitializeTimer((PDEVICE_OBJECT)RdrDeviceObject, RdrIdleTimer, NULL);
  148. return;
  149. }