tthread.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. {
  2. $Id$
  3. This file is part of the Free Component Library (FCL)
  4. Copyright (c) 1999-2002 by the Free Pascal development team
  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. {* TThread *}
  13. {****************************************************************************}
  14. {$WARNING This file is only a stub, and will not work!}
  15. const
  16. ThreadCount: longint = 0;
  17. (* Implementation of exported functions *)
  18. procedure AddThread (T: TThread);
  19. begin
  20. Inc (ThreadCount);
  21. end;
  22. procedure RemoveThread (T: TThread);
  23. begin
  24. Dec (ThreadCount);
  25. end;
  26. procedure TThread.CallOnTerminate;
  27. begin
  28. FOnTerminate (Self);
  29. end;
  30. function TThread.GetPriority: TThreadPriority;
  31. var
  32. { PTIB: PThreadInfoBlock;
  33. PPIB: PProcessInfoBlock;}
  34. I: TThreadPriority;
  35. begin
  36. {
  37. DosGetInfoBlocks (@PTIB, @PPIB);
  38. with PTIB^.TIB2^ do
  39. if Priority >= $300 then GetPriority := tpTimeCritical else
  40. if Priority < $200 then GetPriority := tpIdle else
  41. begin
  42. I := Succ (Low (TThreadPriority));
  43. while (I < High (TThreadPriority)) and
  44. (Priority - Priorities [I] <= Priorities [Succ (I)] - Priority) do Inc (I);
  45. GetPriority := I;
  46. end;
  47. }
  48. end;
  49. procedure TThread.SetPriority(Value: TThreadPriority);
  50. {var
  51. PTIB: PThreadInfoBlock;
  52. PPIB: PProcessInfoBlock;}
  53. begin
  54. { DosGetInfoBlocks (@PTIB, @PPIB);}
  55. (*
  56. PTIB^.TIB2^.Priority := Priorities [Value];
  57. *)
  58. {
  59. DosSetPriority (2, High (Priorities [Value]),
  60. Low (Priorities [Value]) - PTIB^.TIB2^.Priority, FHandle);}
  61. end;
  62. procedure TThread.SetSuspended(Value: Boolean);
  63. begin
  64. if Value <> FSuspended then
  65. begin
  66. if Value then Suspend else Resume;
  67. end;
  68. end;
  69. procedure TThread.DoTerminate;
  70. begin
  71. if Assigned (FOnTerminate) then Synchronize (@CallOnTerminate);
  72. end;
  73. procedure TThread.Synchronize(Method: TThreadMethod);
  74. begin
  75. end;
  76. function ThreadProc(Args: pointer): Integer; cdecl;
  77. var
  78. FreeThread: Boolean;
  79. Thread: TThread absolute Args;
  80. begin
  81. try
  82. Thread.Execute;
  83. except
  84. Thread.FFatalException := TObject(AcquireExceptionObject);
  85. end;
  86. FreeThread := Thread.FFreeOnTerminate;
  87. Result := Thread.FReturnValue;
  88. Thread.FFinished := True;
  89. Thread.DoTerminate;
  90. if FreeThread then Thread.Free;
  91. {
  92. DosExit (deThread, Result);
  93. }
  94. end;
  95. constructor TThread.Create(CreateSuspended: Boolean);
  96. var
  97. Flags: cardinal;
  98. begin
  99. inherited Create;
  100. AddThread (Self);
  101. {
  102. FSuspended := CreateSuspended;
  103. Flags := dtStack_Commited;
  104. if FSuspended then Flags := Flags or dtSuspended;
  105. if DosCreateThread (cardinal (FThreadID), @ThreadProc, pointer (Self),
  106. Flags, 16384) <> 0 then
  107. begin
  108. FFinished := true;
  109. Destroy;
  110. end else FHandle := FThreadID;
  111. IsMultiThread := true;
  112. FFatalException := nil;
  113. }
  114. end;
  115. destructor TThread.Destroy;
  116. begin
  117. if not FFinished and not Suspended then
  118. begin
  119. Terminate;
  120. WaitFor;
  121. end;
  122. {
  123. if FHandle <> -1 then DosKillThread (cardinal (FHandle));
  124. FFatalException.Free;
  125. FFatalException := nil;
  126. inherited Destroy;
  127. RemoveThread (Self);
  128. }
  129. end;
  130. procedure TThread.Resume;
  131. begin
  132. { FSuspended := not (DosResumeThread (cardinal (FHandle)) = 0);}
  133. end;
  134. procedure TThread.Suspend;
  135. begin
  136. { FSuspended := DosSuspendThread (cardinal (FHandle)) = 0;}
  137. end;
  138. procedure TThread.Terminate;
  139. begin
  140. FTerminated := true;
  141. end;
  142. function TThread.WaitFor: Integer;
  143. var
  144. FH: cardinal;
  145. begin
  146. { WaitFor := DosWaitThread (FH, dtWait);}
  147. end;
  148. {
  149. $Log$
  150. Revision 1.1 2004-06-06 14:45:20 karoly
  151. * dummy file to have classes compiled, still needs lot of work
  152. }