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.

160 lines
3.8 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. net\routing\ipx\sap\asresmgr.c
  5. Abstract:
  6. Asyncronous result reporting queue manager
  7. Author:
  8. Vadim Eydelman 05-15-1995
  9. Revision History:
  10. --*/
  11. #include "sapp.h"
  12. typedef struct _RESULT_QUEUE {
  13. CRITICAL_SECTION RQ_Lock;
  14. LIST_ENTRY RQ_Head;
  15. HANDLE RQ_Event;
  16. } RESULT_QUEUE, *PRESULT_QUEUE;
  17. RESULT_QUEUE ResultQueue;
  18. /*++
  19. *******************************************************************
  20. C r e a t e R e s u l t Q u e u e
  21. Routine Description:
  22. Allocates resources for result queue
  23. Arguments:
  24. NotificationEvent - event to be signalled when queue is not empty
  25. Return Value:
  26. NO_ERROR - resources were allocated successfully
  27. other - reason of failure (windows error code)
  28. *******************************************************************
  29. --*/
  30. DWORD
  31. CreateResultQueue (
  32. IN HANDLE NotificationEvent
  33. ) {
  34. ResultQueue.RQ_Event = NotificationEvent;
  35. InitializeCriticalSection (&ResultQueue.RQ_Lock);
  36. InitializeListHead (&ResultQueue.RQ_Head);
  37. return NO_ERROR;
  38. }
  39. /*++
  40. *******************************************************************
  41. D e l e t e R e s u l t Q u e u e
  42. Routine Description:
  43. Dispose of resources allocated for result queue
  44. Arguments:
  45. None
  46. Return Value:
  47. None
  48. *******************************************************************
  49. --*/
  50. VOID
  51. DeleteResultQueue (
  52. void
  53. ) {
  54. while (!IsListEmpty (&ResultQueue.RQ_Head)) {
  55. PAR_PARAM_BLOCK rslt = CONTAINING_RECORD (
  56. ResultQueue.RQ_Head.Flink,
  57. AR_PARAM_BLOCK,
  58. link);
  59. Trace (DEBUG_FAILURES, "File: %s, line %ld."
  60. "Releasing pending message %d for RM.",
  61. __FILE__, __LINE__, rslt->event);
  62. RemoveEntryList (&rslt->link);
  63. (*rslt->freeRsltCB) (rslt);
  64. }
  65. DeleteCriticalSection (&ResultQueue.RQ_Lock);
  66. }
  67. /*++
  68. *******************************************************************
  69. E n q u e u e R e s u l t
  70. Routine Description:
  71. Enqueues message in result queue
  72. Arguments:
  73. rslt - result param block with enqueued message
  74. Return Value:
  75. None
  76. *******************************************************************
  77. --*/
  78. VOID
  79. EnqueueResult (
  80. PAR_PARAM_BLOCK rslt
  81. ) {
  82. BOOL setEvent;
  83. EnterCriticalSection (&ResultQueue.RQ_Lock);
  84. setEvent = IsListEmpty (&ResultQueue.RQ_Head);
  85. InsertTailList (&ResultQueue.RQ_Head, &rslt->link);
  86. LeaveCriticalSection (&ResultQueue.RQ_Lock);
  87. Trace (DEBUG_ASYNCRESULT, "Enqueing message %d for RM.", rslt->event);
  88. if (setEvent) {
  89. BOOL res = SetEvent (ResultQueue.RQ_Event);
  90. ASSERTERRMSG ("Could not set result event ", res);
  91. Trace (DEBUG_ASYNCRESULT, "Signaling RM event.");
  92. }
  93. }
  94. /*++
  95. *******************************************************************
  96. S a p G e t E v e n t R e s u l t
  97. Routine Description:
  98. Gets first message form result queue
  99. Arguments:
  100. Event - buffer to store event for which this message is intended
  101. Message - buffer to store message itself
  102. Return Value:
  103. NO_ERROR - message was dequeued
  104. ERROR_NO_MORE_ITEMS - no more messages in the queue
  105. *******************************************************************
  106. --*/
  107. DWORD
  108. SapGetEventResult(
  109. OUT ROUTING_PROTOCOL_EVENTS *Event,
  110. OUT MESSAGE *Message
  111. ) {
  112. DWORD status;
  113. EnterCriticalSection (&ResultQueue.RQ_Lock);
  114. if (!IsListEmpty (&ResultQueue.RQ_Head)) {
  115. PAR_PARAM_BLOCK rslt = CONTAINING_RECORD (
  116. ResultQueue.RQ_Head.Flink,
  117. AR_PARAM_BLOCK,
  118. link);
  119. RemoveEntryList (&rslt->link);
  120. *Event = rslt->event;
  121. memcpy (Message, &rslt->message, sizeof (*Message));
  122. status = NO_ERROR;
  123. LeaveCriticalSection (&ResultQueue.RQ_Lock);
  124. (*rslt->freeRsltCB) (rslt);
  125. Trace (DEBUG_ASYNCRESULT, "Reporting event %d to RM");
  126. }
  127. else {
  128. LeaveCriticalSection (&ResultQueue.RQ_Lock);
  129. status = ERROR_NO_MORE_ITEMS;
  130. Trace (DEBUG_ASYNCRESULT, "No more items in RM result queue");
  131. }
  132. return status;
  133. }