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.

153 lines
3.5 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: CSendQueue.h
  6. * Content: Queue to manage outgoing sends
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 06/14/99 jtk Created
  13. ***************************************************************************/
  14. #ifndef __SEND_QUEUE_H__
  15. #define __SEND_QUEUE_H__
  16. //**********************************************************************
  17. // Constant definitions
  18. //**********************************************************************
  19. //**********************************************************************
  20. // Macro definitions
  21. //**********************************************************************
  22. //**********************************************************************
  23. // Structure definitions
  24. //**********************************************************************
  25. //**********************************************************************
  26. // Variable definitions
  27. //**********************************************************************
  28. //**********************************************************************
  29. // Function prototypes
  30. //**********************************************************************
  31. //**********************************************************************
  32. // Class definition
  33. //**********************************************************************
  34. //
  35. // forward structure references
  36. //
  37. class CModemEndpoint;
  38. class CModemWriteIOData;
  39. //
  40. // main class definition
  41. //
  42. class CSendQueue
  43. {
  44. public:
  45. CSendQueue();
  46. ~CSendQueue();
  47. void Lock( void ) { DNEnterCriticalSection( &m_Lock ); }
  48. void Unlock( void ) { DNLeaveCriticalSection( &m_Lock ); }
  49. HRESULT Initialize( void );
  50. void Deinitialize( void ) { DNDeleteCriticalSection( &m_Lock ); }
  51. //
  52. // add item to end of queue
  53. //
  54. void Enqueue( CModemWriteIOData *const pWriteData )
  55. {
  56. AssertCriticalSectionIsTakenByThisThread( &m_Lock, TRUE );
  57. if ( m_pTail == NULL )
  58. {
  59. m_pHead = pWriteData;
  60. }
  61. else
  62. {
  63. m_pTail->m_pNext = pWriteData;
  64. }
  65. m_pTail = pWriteData;
  66. pWriteData->m_pNext = NULL;
  67. }
  68. //
  69. // add item to front of queue
  70. //
  71. void AddToFront( CModemWriteIOData *const pWriteData )
  72. {
  73. AssertCriticalSectionIsTakenByThisThread( &m_Lock, TRUE );
  74. if ( m_pHead != NULL )
  75. {
  76. pWriteData->m_pNext = m_pHead;
  77. }
  78. else
  79. {
  80. m_pTail = pWriteData;
  81. pWriteData->m_pNext = NULL;
  82. }
  83. m_pHead = pWriteData;
  84. }
  85. //
  86. // remove item from queue
  87. //
  88. CModemWriteIOData *Dequeue( void )
  89. {
  90. CModemWriteIOData *pReturn;
  91. AssertCriticalSectionIsTakenByThisThread( &m_Lock, TRUE );
  92. pReturn = m_pHead;
  93. if ( m_pHead != NULL )
  94. {
  95. m_pHead = m_pHead->m_pNext;
  96. if ( m_pHead == NULL )
  97. {
  98. m_pTail = NULL;
  99. }
  100. DEBUG_ONLY( pReturn->m_pNext = NULL );
  101. }
  102. return pReturn;
  103. };
  104. //
  105. // determine if queue is empty
  106. //
  107. #undef DPF_MODNAME
  108. #define DPF_MODNAME "CSendQueue::IsEmpty"
  109. BOOL IsEmpty( void ) const
  110. {
  111. AssertCriticalSectionIsTakenByThisThread( &m_Lock, TRUE );
  112. if ( m_pHead == NULL )
  113. {
  114. DNASSERT( m_pTail == NULL );
  115. return TRUE;
  116. }
  117. else
  118. {
  119. return FALSE;
  120. }
  121. }
  122. protected:
  123. private:
  124. DNCRITICAL_SECTION m_Lock; // critical section
  125. CModemWriteIOData *m_pHead; // pointer to queue head
  126. CModemWriteIOData *m_pTail; // pointer to queue tail
  127. };
  128. #endif // __SEND_QUEUE_H__