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.

158 lines
4.2 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 2000-2000 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: JobQueue.h
  6. * Content: Job queue for thread pool
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 01/24/2000 jtk Created
  12. ***************************************************************************/
  13. #ifndef __JOB_QUEUE_H__
  14. #define __JOB_QUEUE_H__
  15. #undef DPF_SUBCOMP
  16. #define DPF_SUBCOMP DN_SUBCOMP_MODEM
  17. //**********************************************************************
  18. // Constant definitions
  19. //**********************************************************************
  20. //**********************************************************************
  21. // Macro definitions
  22. //**********************************************************************
  23. //**********************************************************************
  24. // Structure definitions
  25. //**********************************************************************
  26. //
  27. // forward structure references
  28. //
  29. class CSocketPort;
  30. typedef enum _JOB_TYPE JOB_TYPE;
  31. typedef struct _THREAD_POOL_JOB THREAD_POOL_JOB;
  32. typedef void JOB_FUNCTION( THREAD_POOL_JOB *const pJobInfo );
  33. //
  34. // structure for job to start monitoring a socket in Win9x
  35. //
  36. typedef struct
  37. {
  38. CSocketPort *pSocketPort; // pointer to associated socket port
  39. } DATA_ADD_SOCKET;
  40. //
  41. // structure for job to stop monitoring a socket in Win9x
  42. //
  43. typedef struct
  44. {
  45. CSocketPort *pSocketPort; // pointer to associated socket port
  46. } DATA_REMOVE_SOCKET;
  47. //
  48. // structure for job to connect
  49. //
  50. typedef struct
  51. {
  52. JOB_FUNCTION *pCommandFunction; // pointer to function for the command
  53. void *pContext; // user context (i.e. CModemEndpoint pointer)
  54. UINT_PTR uData; // user data
  55. } DATA_DELAYED_COMMAND;
  56. //
  57. // structure for job to refresh enums
  58. //
  59. typedef struct
  60. {
  61. UINT_PTR uDummy; // dummy variable to prevent compiler from whining
  62. } DATA_REFRESH_TIMED_JOBS;
  63. //
  64. // structure encompassing information for a job for the workhorse thread
  65. //
  66. typedef struct _THREAD_POOL_JOB
  67. {
  68. THREAD_POOL_JOB *pNext; // pointer to next job
  69. JOB_TYPE JobType; // type of job
  70. JOB_FUNCTION *pCancelFunction; // function for cancelling job
  71. // DWORD dwCommandID; // unique ID used to identify this command
  72. // FUNCTION *pProcessFunction; // function for performing job
  73. union
  74. {
  75. DATA_DELAYED_COMMAND JobDelayedCommand;
  76. DATA_REMOVE_SOCKET JobRemoveSocket;
  77. DATA_ADD_SOCKET JobAddSocket;
  78. DATA_REFRESH_TIMED_JOBS JobRefreshTimedJobs;
  79. } JobData;
  80. } THREAD_POOL_JOB;
  81. //**********************************************************************
  82. // Variable definitions
  83. //**********************************************************************
  84. //**********************************************************************
  85. // Function prototypes
  86. //**********************************************************************
  87. //**********************************************************************
  88. // Class prototypes
  89. //**********************************************************************
  90. //
  91. // class to encapsultate a job queue
  92. //
  93. class CJobQueue
  94. {
  95. public:
  96. BOOL Initialize( void );
  97. void Deinitialize( void );
  98. void Lock( void ) { DNEnterCriticalSection( &m_Lock ); }
  99. void Unlock( void ) { DNLeaveCriticalSection( &m_Lock ); }
  100. #undef DPF_MODNAME
  101. #define DPF_MODNAME "CJobQueue::GetPendingJobHandle"
  102. DNHANDLE GetPendingJobHandle( void ) const
  103. {
  104. DNASSERT( m_hPendingJob != NULL );
  105. return m_hPendingJob;
  106. }
  107. BOOL SignalPendingJob( void );
  108. BOOL IsEmpty( void ) const { return ( m_pQueueHead == NULL ); }
  109. void EnqueueJob( THREAD_POOL_JOB *const pJob );
  110. THREAD_POOL_JOB *DequeueJob( void );
  111. protected:
  112. private:
  113. #ifndef DPNBUILD_ONLYONETHREAD
  114. DNCRITICAL_SECTION m_Lock; // lock
  115. #endif // !DPNBUILD_ONLYONETHREAD
  116. THREAD_POOL_JOB *m_pQueueHead; // head of job queue
  117. THREAD_POOL_JOB *m_pQueueTail; // tail of job queue
  118. DNHANDLE m_hPendingJob; // event indicating a pending job
  119. //
  120. // prevent unwarranted copies
  121. //
  122. CJobQueue( const CJobQueue & );
  123. CJobQueue& operator=( const CJobQueue & );
  124. };
  125. #undef DPF_MODNAME
  126. #endif // __JOB_QUEUE_H__