systhrd.inc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. {*****************************************************************************
  96. Delphi/Win32 compatibility
  97. *****************************************************************************}
  98. procedure SysInitCriticalSection(var cs);
  99. begin
  100. Pointer(cs) := GetMem(SizeOf(Pointer));
  101. end;
  102. procedure SysDoneCriticalSection(var cs);
  103. begin
  104. FreeMem(Pointer(cs));
  105. end;
  106. procedure SysEnterCriticalSection(var cs);
  107. begin
  108. end;
  109. function SysTryEnterCriticalSection(var cs):longint;
  110. begin
  111. Result := STATUS_NOT_IMPLEMENTED;
  112. end;
  113. procedure SysLeaveCriticalSection(var cs);
  114. begin
  115. end;
  116. function intBasicEventCreate(EventAttributes : Pointer;
  117. AManualReset,InitialState : Boolean;const Name : ansistring):pEventState;
  118. begin
  119. Result := GetMem(SizeOf(Pointer));
  120. end;
  121. procedure intbasiceventdestroy(state:peventstate);
  122. begin
  123. FreeMem(state);
  124. end;
  125. procedure intbasiceventResetEvent(state:peventstate);
  126. begin
  127. end;
  128. procedure intbasiceventSetEvent(state:peventstate);
  129. begin
  130. end;
  131. function intbasiceventWaitFor(Timeout : Cardinal;state:peventstate) : longint;
  132. begin
  133. Result := STATUS_NOT_IMPLEMENTED;
  134. end;
  135. function intRTLEventCreate: PRTLEvent;
  136. begin
  137. Result := GetMem(SizeOf(Pointer));
  138. end;
  139. procedure intRTLEventDestroy(AEvent: PRTLEvent);
  140. begin
  141. FreeMem(AEvent);
  142. end;
  143. procedure intRTLEventSetEvent(AEvent: PRTLEvent);
  144. begin
  145. end;
  146. procedure intRTLEventResetEvent(AEvent: PRTLEvent);
  147. begin
  148. end;
  149. procedure intRTLEventWaitFor(AEvent: PRTLEvent);
  150. begin
  151. end;
  152. procedure intRTLEventWaitForTimeout(AEvent: PRTLEvent;timeout : longint);
  153. begin
  154. end;
  155. Var
  156. NTThreadManager : TThreadManager;
  157. Procedure InitSystemThreads;
  158. begin
  159. With NTThreadManager do
  160. begin
  161. InitManager :=Nil;
  162. DoneManager :=Nil;
  163. BeginThread :=@SysBeginThread;
  164. EndThread :=@SysEndThread;
  165. SuspendThread :=@SysSuspendThread;
  166. ResumeThread :=@SysResumeThread;
  167. KillThread :=@SysKillThread;
  168. ThreadSwitch :=@SysThreadSwitch;
  169. CloseThread :=@SysCloseThread;
  170. WaitForThreadTerminate :=@SysWaitForThreadTerminate;
  171. ThreadSetPriority :=@SysThreadSetPriority;
  172. ThreadGetPriority :=@SysThreadGetPriority;
  173. GetCurrentThreadId :=@SysGetCurrentThreadId;
  174. InitCriticalSection :=@SysInitCriticalSection;
  175. DoneCriticalSection :=@SysDoneCriticalSection;
  176. EnterCriticalSection :=@SysEnterCriticalSection;
  177. TryEnterCriticalSection:=@SysTryEnterCriticalSection;
  178. LeaveCriticalSection :=@SysLeaveCriticalSection;
  179. InitThreadVar :=@SysInitThreadVar;
  180. RelocateThreadVar :=@SysRelocateThreadVar;
  181. AllocateThreadVars :=@SysAllocateThreadVars;
  182. ReleaseThreadVars :=@SysReleaseThreadVars;
  183. BasicEventCreate :=@intBasicEventCreate;
  184. BasicEventDestroy :=@intBasicEventDestroy;
  185. BasicEventResetEvent :=@intBasicEventResetEvent;
  186. BasicEventSetEvent :=@intBasicEventSetEvent;
  187. BasiceventWaitFor :=@intBasiceventWaitFor;
  188. RTLEventCreate :=@intRTLEventCreate;
  189. RTLEventDestroy :=@intRTLEventDestroy;
  190. RTLEventSetEvent :=@intRTLEventSetEvent;
  191. RTLEventResetEvent :=@intRTLEventResetEvent;
  192. RTLEventWaitFor :=@intRTLEventWaitFor;
  193. RTLEventWaitForTimeout :=@intRTLEventWaitForTimeout;
  194. end;
  195. SetThreadManager(NTThreadManager);
  196. { ThreadID := GetCurrentThreadID;
  197. if IsLibrary then
  198. SysInitMultithreading;}
  199. end;