Leaked source code of windows server 2003
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.

149 lines
3.2 KiB

  1. /*++
  2. Module Name:
  3. purge.c
  4. Environment:
  5. Kernel mode
  6. Revision History :
  7. --*/
  8. #include "precomp.h"
  9. NTSTATUS
  10. MoxaStartPurge(
  11. IN PMOXA_DEVICE_EXTENSION Extension
  12. )
  13. {
  14. PIRP newIrp;
  15. do {
  16. ULONG mask;
  17. mask = *((ULONG *)
  18. (Extension->CurrentPurgeIrp->AssociatedIrp.SystemBuffer));
  19. if (mask & SERIAL_PURGE_TXABORT) {
  20. KIRQL oldIrql;
  21. MoxaKillAllReadsOrWrites(
  22. Extension->DeviceObject,
  23. &Extension->WriteQueue,
  24. &Extension->CurrentWriteIrp
  25. );
  26. //
  27. // Clean out the Tx queue
  28. //
  29. KeAcquireSpinLock(
  30. &Extension->ControlLock,
  31. &oldIrql
  32. );
  33. Extension->TotalCharsQueued = 0;
  34. MoxaFunc( // flush output queue
  35. Extension->PortOfs,
  36. FC_FlushQueue,
  37. 1
  38. );
  39. KeReleaseSpinLock(
  40. &Extension->ControlLock,
  41. oldIrql
  42. );
  43. }
  44. if (mask & SERIAL_PURGE_RXABORT) {
  45. MoxaKillAllReadsOrWrites(
  46. Extension->DeviceObject,
  47. &Extension->ReadQueue,
  48. &Extension->CurrentReadIrp
  49. );
  50. }
  51. if (mask & SERIAL_PURGE_TXCLEAR) {
  52. KIRQL oldIrql;
  53. //
  54. // Clean out the Tx queue
  55. //
  56. KeAcquireSpinLock(
  57. &Extension->ControlLock,
  58. &oldIrql
  59. );
  60. MoxaFunc( // flush output queue
  61. Extension->PortOfs,
  62. FC_FlushQueue,
  63. 1
  64. );
  65. KeReleaseSpinLock(
  66. &Extension->ControlLock,
  67. oldIrql
  68. );
  69. }
  70. if (mask & SERIAL_PURGE_RXCLEAR) {
  71. KIRQL oldIrql;
  72. //
  73. // Clean out the Rx queue
  74. //
  75. // Note that we do this under protection of the
  76. // the drivers control lock so that we don't hose
  77. // the pointers if there is currently a read that
  78. // is reading out of the buffer.
  79. //
  80. KeAcquireSpinLock(
  81. &Extension->ControlLock,
  82. &oldIrql
  83. );
  84. MoxaFunc( // flush input queue
  85. Extension->PortOfs,
  86. FC_FlushQueue,
  87. 0
  88. );
  89. KeReleaseSpinLock(
  90. &Extension->ControlLock,
  91. oldIrql
  92. );
  93. }
  94. Extension->CurrentPurgeIrp->IoStatus.Status = STATUS_SUCCESS;
  95. Extension->CurrentPurgeIrp->IoStatus.Information = 0;
  96. MoxaGetNextIrp(
  97. &Extension->CurrentPurgeIrp,
  98. &Extension->PurgeQueue,
  99. &newIrp,
  100. TRUE,
  101. Extension
  102. );
  103. } while (newIrp);
  104. return STATUS_SUCCESS;
  105. }
  106.