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.

192 lines
4.3 KiB

  1. //============================================================================
  2. // Copyright (c) 1995, Microsoft Corporation
  3. //
  4. // File: queue.c
  5. //
  6. // History:
  7. // Abolade Gbadegesin Aug-8-1995 Created.
  8. //
  9. // timer queue, change queue, and event message queue implementation
  10. //============================================================================
  11. #include "pchbootp.h"
  12. //----------------------------------------------------------------------------
  13. // Function: EnqueueEvent
  14. //
  15. // This function adds an entry to the end of the queue of
  16. // Router Manager events. It assumes the queue is locked.
  17. //----------------------------------------------------------------------------
  18. DWORD
  19. EnqueueEvent(
  20. PLOCKED_LIST pQueue,
  21. ROUTING_PROTOCOL_EVENTS Event,
  22. MESSAGE Result
  23. ) {
  24. DWORD dwErr;
  25. PLIST_ENTRY phead;
  26. PEVENT_QUEUE_ENTRY peqe;
  27. phead = &pQueue->LL_Head;
  28. peqe = BOOTP_ALLOC(sizeof(EVENT_QUEUE_ENTRY));
  29. if (peqe == NULL) {
  30. dwErr = GetLastError();
  31. TRACE2(
  32. ANY, "error %d allocating %d bytes for event queue",
  33. dwErr, sizeof(EVENT_QUEUE_ENTRY)
  34. );
  35. LOGERR0(HEAP_ALLOC_FAILED, dwErr);
  36. return dwErr;
  37. }
  38. peqe->EQE_Event = Event;
  39. peqe->EQE_Result = Result;
  40. InsertTailList(phead, &peqe->EQE_Link);
  41. return NO_ERROR;
  42. }
  43. //----------------------------------------------------------------------------
  44. // Function: DequeueEvent
  45. //
  46. // This function removes an entry from the head of the queue
  47. // of Router Manager events. It assumes the queue is locked
  48. //----------------------------------------------------------------------------
  49. DWORD
  50. DequeueEvent(
  51. PLOCKED_LIST pQueue,
  52. ROUTING_PROTOCOL_EVENTS *pEvent,
  53. PMESSAGE pResult
  54. ) {
  55. PLIST_ENTRY phead, ple;
  56. PEVENT_QUEUE_ENTRY peqe;
  57. phead = &pQueue->LL_Head;
  58. if (IsListEmpty(phead)) {
  59. return ERROR_NO_MORE_ITEMS;
  60. }
  61. ple = RemoveHeadList(phead);
  62. peqe = CONTAINING_RECORD(ple, EVENT_QUEUE_ENTRY, EQE_Link);
  63. *pEvent = peqe->EQE_Event;
  64. *pResult = peqe->EQE_Result;
  65. BOOTP_FREE(peqe);
  66. return NO_ERROR;
  67. }
  68. //----------------------------------------------------------------------------
  69. // Function: EnqueueRecvEntry
  70. //
  71. // assumes that recv queue is locked and that global config is locked
  72. // for reading or writing
  73. //----------------------------------------------------------------------------
  74. DWORD
  75. EnqueueRecvEntry(
  76. PLOCKED_LIST pQueue,
  77. DWORD dwCommand,
  78. PBYTE pRoutes
  79. ) {
  80. DWORD dwErr;
  81. PLIST_ENTRY phead;
  82. PRECV_QUEUE_ENTRY prqe;
  83. //
  84. // check that the max queue size is not exceeded
  85. //
  86. if ((DWORD)ig.IG_RecvQueueSize >= ig.IG_Config->GC_MaxRecvQueueSize) {
  87. TRACE2(
  88. RECEIVE,
  89. "dropping route: recv queue size is %d bytes and max is %d bytes",
  90. ig.IG_RecvQueueSize, ig.IG_Config->GC_MaxRecvQueueSize
  91. );
  92. return ERROR_INSUFFICIENT_BUFFER;
  93. }
  94. phead = &pQueue->LL_Head;
  95. prqe = BOOTP_ALLOC(sizeof(RECV_QUEUE_ENTRY));
  96. if (prqe == NULL) {
  97. dwErr = GetLastError();
  98. TRACE2(
  99. ANY, "error %d allocating %d bytes for recv-queue entry",
  100. dwErr, sizeof(RECV_QUEUE_ENTRY)
  101. );
  102. LOGERR0(HEAP_ALLOC_FAILED, dwErr);
  103. return dwErr;
  104. }
  105. prqe->RQE_Routes = pRoutes;
  106. prqe->RQE_Command = dwCommand;
  107. InsertTailList(phead, &prqe->RQE_Link);
  108. ig.IG_RecvQueueSize += sizeof(RECV_QUEUE_ENTRY);
  109. return NO_ERROR;
  110. }
  111. //----------------------------------------------------------------------------
  112. // Function: DequeueRecvEntry
  113. //
  114. // assumes that recv queue is locked
  115. //----------------------------------------------------------------------------
  116. DWORD
  117. DequeueRecvEntry(
  118. PLOCKED_LIST pQueue,
  119. PDWORD pdwCommand,
  120. PBYTE *ppRoutes
  121. ) {
  122. PLIST_ENTRY ple, phead;
  123. PRECV_QUEUE_ENTRY prqe;
  124. phead = &pQueue->LL_Head;
  125. if (IsListEmpty(phead)) { return ERROR_NO_MORE_ITEMS; }
  126. ple = RemoveHeadList(phead);
  127. prqe = CONTAINING_RECORD(ple, RECV_QUEUE_ENTRY, RQE_Link);
  128. *ppRoutes = prqe->RQE_Routes;
  129. *pdwCommand = prqe->RQE_Command;
  130. BOOTP_FREE(prqe);
  131. ig.IG_RecvQueueSize -= sizeof(RECV_QUEUE_ENTRY);
  132. if (ig.IG_RecvQueueSize < 0) { ig.IG_RecvQueueSize = 0; }
  133. return NO_ERROR;
  134. }