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.

227 lines
6.3 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 2001 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dp8simjob.h
  6. *
  7. * Content: Header for job object class.
  8. *
  9. * History:
  10. * Date By Reason
  11. * ======== ======== =========
  12. * 06/09/01 VanceO Created.
  13. *
  14. ***************************************************************************/
  15. //=============================================================================
  16. // Macros
  17. //=============================================================================
  18. #define DP8SIMJOB_FROM_BILINK(b) (CONTAINING_OBJECT(b, CDP8SimJob, m_blList))
  19. //=============================================================================
  20. // Private job flags
  21. //=============================================================================
  22. #define DP8SIMJOBFLAG_PRIVATE_INBLOCKINGPHASE 0x80000000 // this job is in its blocking phase
  23. //=============================================================================
  24. // Structures
  25. //=============================================================================
  26. typedef struct _DP8SIMJOB_FPMCONTEXT
  27. {
  28. DWORD dwTime; // time for the job to fire
  29. DWORD dwNextDelay; // possible extra delay for the job after this first timer elapses
  30. DWORD dwFlags; // flags describing this job
  31. DP8SIMJOBTYPE JobType; // type of job
  32. PVOID pvContext; // context for job
  33. CDP8SimSP * pDP8SimSP; // owning SP object, if any
  34. } DP8SIMJOB_FPMCONTEXT, * PDP8SIMJOB_FPMCONTEXT;
  35. //=============================================================================
  36. // Job object class
  37. //=============================================================================
  38. class CDP8SimJob
  39. {
  40. public:
  41. inline BOOL IsValidObject(void)
  42. {
  43. if ((this == NULL) || (IsBadWritePtr(this, sizeof(CDP8SimJob))))
  44. {
  45. return FALSE;
  46. }
  47. if (*((DWORD*) (&this->m_Sig)) != 0x4a4d4953) // 0x4a 0x4d 0x49 0x53 = 'JMIS' = 'SIMJ' in Intel order
  48. {
  49. return FALSE;
  50. }
  51. return TRUE;
  52. };
  53. static BOOL FPMAlloc(void* pvItem, void* pvContext)
  54. {
  55. CDP8SimJob * pDP8SimJob = (CDP8SimJob*) pvItem;
  56. pDP8SimJob->m_Sig[0] = 'S';
  57. pDP8SimJob->m_Sig[1] = 'I';
  58. pDP8SimJob->m_Sig[2] = 'M';
  59. pDP8SimJob->m_Sig[3] = 'j'; // start with lower case so we can tell when it's in the pool or not
  60. pDP8SimJob->m_blList.Initialize();
  61. pDP8SimJob->m_dwTime = 0;
  62. pDP8SimJob->m_dwNextDelay = 0;
  63. pDP8SimJob->m_dwFlags = 0;
  64. pDP8SimJob->m_JobType = DP8SIMJOBTYPE_UNKNOWN;
  65. pDP8SimJob->m_pvContext = NULL;
  66. pDP8SimJob->m_pDP8SimSP = NULL;
  67. return TRUE;
  68. }
  69. #undef DPF_MODNAME
  70. #define DPF_MODNAME "CDP8SimJob::FPMInitialize"
  71. static void FPMInitialize(void* pvItem, void* pvContext)
  72. {
  73. CDP8SimJob * pDP8SimJob = (CDP8SimJob*) pvItem;
  74. DP8SIMJOB_FPMCONTEXT * pContext = (DP8SIMJOB_FPMCONTEXT*) pvContext;
  75. pDP8SimJob->m_dwTime = pContext->dwTime;
  76. pDP8SimJob->m_dwNextDelay = pContext->dwNextDelay;
  77. pDP8SimJob->m_dwFlags = pContext->dwFlags;
  78. pDP8SimJob->m_JobType = pContext->JobType;
  79. pDP8SimJob->m_pvContext = pContext->pvContext;
  80. if (pContext->pDP8SimSP != NULL)
  81. {
  82. pContext->pDP8SimSP->AddRef();
  83. pDP8SimJob->m_pDP8SimSP = pContext->pDP8SimSP;
  84. }
  85. else
  86. {
  87. DNASSERT(pDP8SimJob->m_pDP8SimSP == NULL);
  88. }
  89. //
  90. // Change the signature before handing it out.
  91. //
  92. pDP8SimJob->m_Sig[3] = 'J';
  93. }
  94. #undef DPF_MODNAME
  95. #define DPF_MODNAME "CDP8SimJob::FPMRelease"
  96. static void FPMRelease(void* pvItem)
  97. {
  98. CDP8SimJob * pDP8SimJob = (CDP8SimJob*) pvItem;
  99. DNASSERT(pDP8SimJob->m_blList.IsEmpty());
  100. if (pDP8SimJob->m_pDP8SimSP != NULL)
  101. {
  102. pDP8SimJob->m_pDP8SimSP->Release();
  103. pDP8SimJob->m_pDP8SimSP = NULL;
  104. }
  105. //
  106. // Change the signature before putting the object back in the pool.
  107. //
  108. pDP8SimJob->m_Sig[3] = 'j';
  109. }
  110. #undef DPF_MODNAME
  111. #define DPF_MODNAME "CDP8SimJob::FPMDealloc"
  112. static void FPMDealloc(void* pvItem)
  113. {
  114. const CDP8SimJob * pDP8SimJob = (CDP8SimJob*) pvItem;
  115. DNASSERT(pDP8SimJob->m_blList.IsEmpty());
  116. DNASSERT(pDP8SimJob->m_pDP8SimSP == NULL);
  117. }
  118. inline DWORD GetTime(void) const { return this->m_dwTime; };
  119. inline DWORD GetNextDelay(void) const { return this->m_dwNextDelay; };
  120. inline BOOL HasAnotherPhase(void) const
  121. {
  122. if (this->m_dwFlags & DP8SIMJOBFLAG_PERFORMBLOCKINGPHASEFIRST)
  123. {
  124. if (this->m_dwFlags & DP8SIMJOBFLAG_PRIVATE_INBLOCKINGPHASE)
  125. {
  126. return TRUE;
  127. }
  128. }
  129. else if (this->m_dwFlags & DP8SIMJOBFLAG_PERFORMBLOCKINGPHASELAST)
  130. {
  131. if (! (this->m_dwFlags & DP8SIMJOBFLAG_PRIVATE_INBLOCKINGPHASE))
  132. {
  133. return TRUE;
  134. }
  135. }
  136. return FALSE;
  137. };
  138. //inline BOOL IsBlockedByAllJobs(void) { return ((this->m_dwFlags & DP8SIMJOBFLAG_BLOCKEDBYALLJOBS) ? TRUE : FALSE); };
  139. inline BOOL IsInBlockingPhase(void) const { return ((this->m_dwFlags & DP8SIMJOBFLAG_PRIVATE_INBLOCKINGPHASE) ? TRUE : FALSE); };
  140. inline DP8SIMJOBTYPE GetJobType(void) const { return this->m_JobType; };
  141. inline PVOID GetContext(void) { return this->m_pvContext; };
  142. inline CDP8SimSP * GetDP8SimSP(void) { return this->m_pDP8SimSP; };
  143. inline void SetNewTime(const DWORD dwTime) { this->m_dwTime = dwTime; };
  144. #undef DPF_MODNAME
  145. #define DPF_MODNAME "CDP8SimJob::ToggleBlockingPhase"
  146. inline void ToggleBlockingPhase(void)
  147. {
  148. DNASSERT(this->m_dwFlags & (DP8SIMJOBFLAG_PERFORMBLOCKINGPHASEFIRST | DP8SIMJOBFLAG_PERFORMBLOCKINGPHASELAST));
  149. if (this->m_dwFlags & DP8SIMJOBFLAG_PRIVATE_INBLOCKINGPHASE)
  150. {
  151. this->m_dwFlags &= ~DP8SIMJOBFLAG_PRIVATE_INBLOCKINGPHASE;
  152. }
  153. else
  154. {
  155. this->m_dwFlags |= DP8SIMJOBFLAG_PRIVATE_INBLOCKINGPHASE;
  156. }
  157. };
  158. CBilink m_blList; // list of all the active jobs
  159. private:
  160. BYTE m_Sig[4]; // debugging signature ('SIMJ')
  161. DWORD m_dwTime; // time the job must be performed
  162. DWORD m_dwNextDelay; // extra delay for the job after first time set
  163. DWORD m_dwFlags; // flags describing this job
  164. DP8SIMJOBTYPE m_JobType; /// ID of job to be performed
  165. PVOID m_pvContext; // context for job
  166. CDP8SimSP * m_pDP8SimSP; // pointer to DP8SimSP object submitting send, or NULL if none
  167. };