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.

233 lines
6.0 KiB

  1. /***************************************************************************\
  2. *
  3. * File: Thread.inl
  4. *
  5. * History:
  6. * 4/18/2000: JStall: Created
  7. *
  8. * Copyright (C) 2000 by Microsoft Corporation. All rights reserved.
  9. *
  10. \***************************************************************************/
  11. #if !defined(SERVICES__Thread_inl__INCLUDED)
  12. #define SERVICES__Thread_inl__INCLUDED
  13. #pragma once
  14. #if USE_DYNAMICTLS
  15. extern DWORD g_tlsThread; // TLS Slot for Thread data
  16. #else
  17. extern __declspec(thread) Thread * t_pThread;
  18. #endif
  19. /***************************************************************************\
  20. *****************************************************************************
  21. *
  22. * class Thread
  23. *
  24. *****************************************************************************
  25. \***************************************************************************/
  26. //------------------------------------------------------------------------------
  27. inline Thread *
  28. GetThread()
  29. {
  30. #if USE_DYNAMICTLS
  31. Thread * pThread = reinterpret_cast<Thread *> (TlsGetValue(g_tlsThread));
  32. #else
  33. Thread * pThread = t_pThread;
  34. #endif
  35. AssertMsg(pThread != NULL, "Thread must already be initialized");
  36. return pThread;
  37. }
  38. //------------------------------------------------------------------------------
  39. inline Thread *
  40. RawGetThread()
  41. {
  42. #if USE_DYNAMICTLS
  43. Thread * pThread = reinterpret_cast<Thread *> (TlsGetValue(g_tlsThread));
  44. #else
  45. Thread * pThread = t_pThread;
  46. #endif
  47. // Don't check if pThread == NULL
  48. return pThread;
  49. }
  50. //------------------------------------------------------------------------------
  51. inline BOOL
  52. IsInitThread()
  53. {
  54. #if USE_DYNAMICTLS
  55. return TlsGetValue(g_tlsThread) != NULL;
  56. #else
  57. return t_pThread != NULL;
  58. #endif
  59. }
  60. //------------------------------------------------------------------------------
  61. inline
  62. Thread::Thread()
  63. {
  64. m_cRef = 1;
  65. }
  66. //------------------------------------------------------------------------------
  67. inline BOOL
  68. Thread::IsSRT() const
  69. {
  70. return m_fSRT;
  71. }
  72. //------------------------------------------------------------------------------
  73. inline void
  74. Thread::Lock()
  75. {
  76. AssertMsg(m_cRef > 0, "Must have a valid reference");
  77. m_cRef++;
  78. }
  79. //------------------------------------------------------------------------------
  80. inline BOOL
  81. Thread::Unlock()
  82. {
  83. AssertMsg(m_cRef > 0, "Must have a valid reference");
  84. return --m_cRef != 0;
  85. }
  86. //------------------------------------------------------------------------------
  87. inline void
  88. Thread::MarkOrphaned()
  89. {
  90. AssertMsg(!m_fOrphaned, "Thread should only be orphaned once");
  91. m_fOrphaned = TRUE;
  92. }
  93. //------------------------------------------------------------------------------
  94. inline GdiCache *
  95. Thread::GetGdiCache() const
  96. {
  97. return const_cast<GdiCache *> (&m_GdiCache);
  98. }
  99. //------------------------------------------------------------------------------
  100. inline BufferManager *
  101. Thread::GetBufferManager() const
  102. {
  103. return const_cast<BufferManager *> (&m_manBuffer);
  104. }
  105. //------------------------------------------------------------------------------
  106. inline ComManager *
  107. Thread::GetComManager() const
  108. {
  109. return const_cast<ComManager *> (&m_manCOM);
  110. }
  111. //------------------------------------------------------------------------------
  112. inline Context *
  113. Thread::GetContext() const
  114. {
  115. return m_pContext;
  116. }
  117. //------------------------------------------------------------------------------
  118. inline void
  119. Thread::SetContext(Context * pContext)
  120. {
  121. AssertMsg(((pContext == NULL) && (m_pContext != NULL)) ||
  122. ((pContext != NULL) && (m_pContext == NULL)) ||
  123. ((pContext == NULL) && (m_pContext == NULL)),
  124. "Must reset Context before changing to a new Context");
  125. m_pContext = pContext;
  126. }
  127. //------------------------------------------------------------------------------
  128. inline SubThread *
  129. Thread::GetST(ESlot slot) const
  130. {
  131. return m_rgSTs[slot];
  132. }
  133. //------------------------------------------------------------------------------
  134. inline void
  135. Thread::xwLeftContextLockNL()
  136. {
  137. for (int idx = 0; idx < slCOUNT; idx++) {
  138. m_rgSTs[idx]->xwLeftContextLockNL();
  139. }
  140. }
  141. //------------------------------------------------------------------------------
  142. inline TempHeap *
  143. Thread::GetTempHeap() const
  144. {
  145. return const_cast<TempHeap *> (&m_heapTemp);
  146. }
  147. //------------------------------------------------------------------------------
  148. inline void
  149. Thread::ReturnMemoryNL(ReturnMem * prMem)
  150. {
  151. prMem->pNext = NULL;
  152. AssertMsg(!m_fDestroySubThreads,
  153. "All memory should be returned before the thread gets destroyed");
  154. m_lstReturn.AddHeadNL(prMem);
  155. }
  156. /***************************************************************************\
  157. *****************************************************************************
  158. *
  159. * class SubThread
  160. *
  161. *****************************************************************************
  162. \***************************************************************************/
  163. //------------------------------------------------------------------------------
  164. inline void
  165. SubThread::SetParent(Thread * pParent)
  166. {
  167. AssertMsg(m_pParent == NULL, "Must set only once");
  168. m_pParent = pParent;
  169. }
  170. /***************************************************************************\
  171. *****************************************************************************
  172. *
  173. * class ThreadPackBuilder
  174. *
  175. *****************************************************************************
  176. \***************************************************************************/
  177. //------------------------------------------------------------------------------
  178. inline ThreadPackBuilder *
  179. ThreadPackBuilder::GetBuilder(Thread::ESlot slot)
  180. {
  181. AssertMsg(s_rgBuilders[slot] != NULL, "Build must be defined");
  182. return s_rgBuilders[slot];
  183. }
  184. #endif // SERVICES__Thread_inl__INCLUDED