systhrd.inc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2010 by Sven Barth
  4. Native NT threading support implementation
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {*****************************************************************************
  12. Native NT API imports
  13. *****************************************************************************}
  14. const
  15. STATUS_NOT_IMPLEMENTED = LongInt($C0000002);
  16. {*****************************************************************************
  17. Threadvar support
  18. *****************************************************************************}
  19. const
  20. threadvarblocksize : dword = 0;
  21. procedure SysInitThreadvar(var offset : dword;size : dword);
  22. begin
  23. offset:=threadvarblocksize;
  24. {$ifdef CPUARM}
  25. // Data must be allocated at 4 bytes boundary for ARM
  26. size:=(size + 3) and not dword(3);
  27. {$endif CPUARM}
  28. inc(threadvarblocksize,size);
  29. end;
  30. procedure SysAllocateThreadVars;
  31. begin
  32. end;
  33. procedure SysInitMultithreading;
  34. begin
  35. end;
  36. procedure SysFiniMultithreading;
  37. begin
  38. end;
  39. function SysRelocateThreadvar(offset : dword) : pointer;
  40. begin
  41. SysRelocateThreadvar:=Pointer(Offset);
  42. end;
  43. procedure SysReleaseThreadVars;
  44. begin
  45. end;
  46. {*****************************************************************************
  47. Thread starting
  48. *****************************************************************************}
  49. function SysBeginThread(sa : Pointer;stacksize : ptruint;
  50. ThreadFunction : tthreadfunc;p : pointer;
  51. creationFlags : dword;var ThreadId : TThreadID) : TThreadID;
  52. begin
  53. ThreadId := 0;
  54. Result := 0;
  55. end;
  56. procedure SysEndThread(ExitCode : DWord);
  57. begin
  58. DoneThread;
  59. end;
  60. procedure SysThreadSwitch;
  61. begin
  62. end;
  63. function SysSuspendThread (threadHandle : TThreadID) : dword;
  64. begin
  65. Result := STATUS_NOT_IMPLEMENTED;
  66. end;
  67. function SysResumeThread (threadHandle : TThreadID) : dword;
  68. begin
  69. Result := STATUS_NOT_IMPLEMENTED;
  70. end;
  71. function SysKillThread (threadHandle : TThreadID) : dword;
  72. begin
  73. Result := STATUS_NOT_IMPLEMENTED;
  74. end;
  75. function SysCloseThread (threadHandle : TThreadID) : dword;
  76. begin
  77. Result := STATUS_NOT_IMPLEMENTED;
  78. end;
  79. function SysWaitForThreadTerminate (threadHandle : TThreadID; TimeoutMs : longint) : dword;
  80. begin
  81. Result := STATUS_NOT_IMPLEMENTED;
  82. end;
  83. function SysThreadSetPriority (threadHandle : TThreadID; Prio: longint): boolean; {-15..+15, 0=normal}
  84. begin
  85. Result := False;
  86. end;
  87. function SysThreadGetPriority (threadHandle : TThreadID): longint;
  88. begin
  89. Result := 0;
  90. end;
  91. function SysGetCurrentThreadId : TThreadID;
  92. begin
  93. Result := 0;
  94. end;
  95. procedure SysSetThreadDebugNameA(threadHandle: TThreadID; const ThreadName: AnsiString);
  96. begin
  97. end;
  98. procedure SysSetThreadDebugNameU(threadHandle: TThreadID; const ThreadName: UnicodeString);
  99. begin
  100. end;
  101. {*****************************************************************************
  102. Delphi/Win32 compatibility
  103. *****************************************************************************}
  104. procedure SysInitCriticalSection(var cs);
  105. begin
  106. Pointer(cs) := GetMem(SizeOf(Pointer));
  107. end;
  108. procedure SysDoneCriticalSection(var cs);
  109. begin
  110. FreeMem(Pointer(cs));
  111. end;
  112. procedure SysEnterCriticalSection(var cs);
  113. begin
  114. end;
  115. function SysTryEnterCriticalSection(var cs):longint;
  116. begin
  117. Result := STATUS_NOT_IMPLEMENTED;
  118. end;
  119. procedure SysLeaveCriticalSection(var cs);
  120. begin
  121. end;
  122. function intBasicEventCreate(EventAttributes : Pointer;
  123. AManualReset,InitialState : Boolean;const Name : ansistring):pEventState;
  124. begin
  125. Result := GetMem(SizeOf(Pointer));
  126. end;
  127. procedure intbasiceventdestroy(state:peventstate);
  128. begin
  129. FreeMem(state);
  130. end;
  131. procedure intbasiceventResetEvent(state:peventstate);
  132. begin
  133. end;
  134. procedure intbasiceventSetEvent(state:peventstate);
  135. begin
  136. end;
  137. function intbasiceventWaitFor(Timeout : Cardinal;state:peventstate;FUseComWait : Boolean=False) : longint;
  138. begin
  139. Result := STATUS_NOT_IMPLEMENTED;
  140. end;
  141. function intRTLEventCreate: PRTLEvent;
  142. begin
  143. Result := GetMem(SizeOf(Pointer));
  144. end;
  145. procedure intRTLEventDestroy(AEvent: PRTLEvent);
  146. begin
  147. FreeMem(AEvent);
  148. end;
  149. procedure intRTLEventSetEvent(AEvent: PRTLEvent);
  150. begin
  151. end;
  152. procedure intRTLEventResetEvent(AEvent: PRTLEvent);
  153. begin
  154. end;
  155. procedure intRTLEventWaitFor(AEvent: PRTLEvent);
  156. begin
  157. end;
  158. procedure intRTLEventWaitForTimeout(AEvent: PRTLEvent;timeout : longint);
  159. begin
  160. end;
  161. Var
  162. NTThreadManager : TThreadManager;
  163. Procedure InitSystemThreads;
  164. begin
  165. With NTThreadManager do
  166. begin
  167. InitManager :=Nil;
  168. DoneManager :=Nil;
  169. BeginThread :=@SysBeginThread;
  170. EndThread :=@SysEndThread;
  171. SuspendThread :=@SysSuspendThread;
  172. ResumeThread :=@SysResumeThread;
  173. KillThread :=@SysKillThread;
  174. ThreadSwitch :=@SysThreadSwitch;
  175. CloseThread :=@SysCloseThread;
  176. WaitForThreadTerminate :=@SysWaitForThreadTerminate;
  177. ThreadSetPriority :=@SysThreadSetPriority;
  178. ThreadGetPriority :=@SysThreadGetPriority;
  179. GetCurrentThreadId :=@SysGetCurrentThreadId;
  180. SetThreadDebugNameA :=@SysSetThreadDebugNameA;
  181. SetThreadDebugNameU :=@SysSetThreadDebugNameU;
  182. InitCriticalSection :=@SysInitCriticalSection;
  183. DoneCriticalSection :=@SysDoneCriticalSection;
  184. EnterCriticalSection :=@SysEnterCriticalSection;
  185. TryEnterCriticalSection:=@SysTryEnterCriticalSection;
  186. LeaveCriticalSection :=@SysLeaveCriticalSection;
  187. InitThreadVar :=@SysInitThreadVar;
  188. RelocateThreadVar :=@SysRelocateThreadVar;
  189. AllocateThreadVars :=@SysAllocateThreadVars;
  190. ReleaseThreadVars :=@SysReleaseThreadVars;
  191. BasicEventCreate :=@intBasicEventCreate;
  192. BasicEventDestroy :=@intBasicEventDestroy;
  193. BasicEventResetEvent :=@intBasicEventResetEvent;
  194. BasicEventSetEvent :=@intBasicEventSetEvent;
  195. BasiceventWaitFor :=@intBasiceventWaitFor;
  196. RTLEventCreate :=@intRTLEventCreate;
  197. RTLEventDestroy :=@intRTLEventDestroy;
  198. RTLEventSetEvent :=@intRTLEventSetEvent;
  199. RTLEventResetEvent :=@intRTLEventResetEvent;
  200. RTLEventWaitFor :=@intRTLEventWaitFor;
  201. RTLEventWaitForTimeout :=@intRTLEventWaitForTimeout;
  202. end;
  203. SetThreadManager(NTThreadManager);
  204. { ThreadID := GetCurrentThreadID;
  205. if IsLibrary then
  206. SysInitMultithreading;}
  207. end;