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.

177 lines
4.2 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. static INT g_iResultInitCount = 0;
  19. VOID
  20. InitializeResultQueue()
  21. {
  22. ZeroMemory(&ResultQueue, sizeof(ResultQueue));
  23. }
  24. /*++
  25. *******************************************************************
  26. C r e a t e R e s u l t Q u e u e
  27. Routine Description:
  28. Allocates resources for result queue
  29. Arguments:
  30. NotificationEvent - event to be signalled when queue is not empty
  31. Return Value:
  32. NO_ERROR - resources were allocated successfully
  33. other - reason of failure (windows error code)
  34. *******************************************************************
  35. --*/
  36. DWORD
  37. CreateResultQueue (
  38. IN HANDLE NotificationEvent
  39. ) {
  40. if (g_iResultInitCount > 0)
  41. {
  42. return NO_ERROR;
  43. }
  44. ResultQueue.RQ_Event = NotificationEvent;
  45. InitializeCriticalSection (&ResultQueue.RQ_Lock);
  46. InitializeListHead (&ResultQueue.RQ_Head);
  47. g_iResultInitCount++;
  48. return NO_ERROR;
  49. }
  50. /*++
  51. *******************************************************************
  52. D e l e t e R e s u l t Q u e u e
  53. Routine Description:
  54. Dispose of resources allocated for result queue
  55. Arguments:
  56. None
  57. Return Value:
  58. None
  59. *******************************************************************
  60. --*/
  61. VOID
  62. DeleteResultQueue (
  63. void
  64. ) {
  65. while (!IsListEmpty (&ResultQueue.RQ_Head)) {
  66. PAR_PARAM_BLOCK rslt = CONTAINING_RECORD (
  67. ResultQueue.RQ_Head.Flink,
  68. AR_PARAM_BLOCK,
  69. link);
  70. Trace (DEBUG_FAILURES, "File: %s, line %ld."
  71. "Releasing pending message %d for RM.",
  72. __FILE__, __LINE__, rslt->event);
  73. RemoveEntryList (&rslt->link);
  74. (*rslt->freeRsltCB) (rslt);
  75. }
  76. DeleteCriticalSection (&ResultQueue.RQ_Lock);
  77. ZeroMemory(&ResultQueue, sizeof(ResultQueue));
  78. g_iResultInitCount--;
  79. }
  80. /*++
  81. *******************************************************************
  82. E n q u e u e R e s u l t
  83. Routine Description:
  84. Enqueues message in result queue
  85. Arguments:
  86. rslt - result param block with enqueued message
  87. Return Value:
  88. None
  89. *******************************************************************
  90. --*/
  91. VOID
  92. EnqueueResult (
  93. PAR_PARAM_BLOCK rslt
  94. ) {
  95. BOOL setEvent;
  96. EnterCriticalSection (&ResultQueue.RQ_Lock);
  97. setEvent = IsListEmpty (&ResultQueue.RQ_Head);
  98. InsertTailList (&ResultQueue.RQ_Head, &rslt->link);
  99. LeaveCriticalSection (&ResultQueue.RQ_Lock);
  100. Trace (DEBUG_ASYNCRESULT, "Enqueing message %d for RM.", rslt->event);
  101. if (setEvent) {
  102. BOOL res = SetEvent (ResultQueue.RQ_Event);
  103. ASSERTERRMSG ("Could not set result event ", res);
  104. Trace (DEBUG_ASYNCRESULT, "Signaling RM event.");
  105. }
  106. }
  107. /*++
  108. *******************************************************************
  109. S a p G e t E v e n t R e s u l t
  110. Routine Description:
  111. Gets first message form result queue
  112. Arguments:
  113. Event - buffer to store event for which this message is intended
  114. Message - buffer to store message itself
  115. Return Value:
  116. NO_ERROR - message was dequeued
  117. ERROR_NO_MORE_ITEMS - no more messages in the queue
  118. *******************************************************************
  119. --*/
  120. DWORD
  121. SapGetEventResult(
  122. OUT ROUTING_PROTOCOL_EVENTS *Event,
  123. OUT MESSAGE *Message
  124. ) {
  125. DWORD status;
  126. EnterCriticalSection (&ResultQueue.RQ_Lock);
  127. if (!IsListEmpty (&ResultQueue.RQ_Head)) {
  128. PAR_PARAM_BLOCK rslt = CONTAINING_RECORD (
  129. ResultQueue.RQ_Head.Flink,
  130. AR_PARAM_BLOCK,
  131. link);
  132. RemoveEntryList (&rslt->link);
  133. *Event = rslt->event;
  134. memcpy (Message, &rslt->message, sizeof (*Message));
  135. status = NO_ERROR;
  136. LeaveCriticalSection (&ResultQueue.RQ_Lock);
  137. (*rslt->freeRsltCB) (rslt);
  138. Trace (DEBUG_ASYNCRESULT, "Reporting event %d to RM");
  139. }
  140. else {
  141. LeaveCriticalSection (&ResultQueue.RQ_Lock);
  142. status = ERROR_NO_MORE_ITEMS;
  143. Trace (DEBUG_ASYNCRESULT, "No more items in RM result queue");
  144. }
  145. return status;
  146. }