tthread.inc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. {
  2. This file is part of the Free Component Library (FCL)
  3. Copyright (c) 1999-2002 by the Free Pascal development team
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. **********************************************************************}
  10. {****************************************************************************}
  11. {* TThread *}
  12. {****************************************************************************}
  13. {$WARNING This file is only a stub, and will not work!}
  14. const
  15. ThreadCount: longint = 0;
  16. (* Implementation of exported functions *)
  17. procedure AddThread (T: TThread);
  18. begin
  19. Inc (ThreadCount);
  20. end;
  21. procedure RemoveThread (T: TThread);
  22. begin
  23. Dec (ThreadCount);
  24. end;
  25. procedure TThread.CallOnTerminate;
  26. begin
  27. FOnTerminate (Self);
  28. end;
  29. function TThread.GetPriority: TThreadPriority;
  30. var
  31. { PTIB: PThreadInfoBlock;
  32. PPIB: PProcessInfoBlock;}
  33. I: TThreadPriority;
  34. begin
  35. {
  36. DosGetInfoBlocks (@PTIB, @PPIB);
  37. with PTIB^.TIB2^ do
  38. if Priority >= $300 then GetPriority := tpTimeCritical else
  39. if Priority < $200 then GetPriority := tpIdle else
  40. begin
  41. I := Succ (Low (TThreadPriority));
  42. while (I < High (TThreadPriority)) and
  43. (Priority - Priorities [I] <= Priorities [Succ (I)] - Priority) do Inc (I);
  44. GetPriority := I;
  45. end;
  46. }
  47. end;
  48. procedure TThread.SetPriority(Value: TThreadPriority);
  49. {var
  50. PTIB: PThreadInfoBlock;
  51. PPIB: PProcessInfoBlock;}
  52. begin
  53. { DosGetInfoBlocks (@PTIB, @PPIB);}
  54. (*
  55. PTIB^.TIB2^.Priority := Priorities [Value];
  56. *)
  57. {
  58. DosSetPriority (2, High (Priorities [Value]),
  59. Low (Priorities [Value]) - PTIB^.TIB2^.Priority, FHandle);}
  60. end;
  61. procedure TThread.SetSuspended(Value: Boolean);
  62. begin
  63. if Value <> FSuspended then
  64. begin
  65. if Value then Suspend else Resume;
  66. end;
  67. end;
  68. procedure TThread.DoTerminate;
  69. begin
  70. if Assigned (FOnTerminate) then Synchronize (@CallOnTerminate);
  71. end;
  72. constructor TThread.Create(CreateSuspended: Boolean;
  73. const StackSize: SizeUInt = DefaultStackSize);
  74. var
  75. Flags: cardinal;
  76. begin
  77. inherited Create;
  78. AddThread (Self);
  79. {
  80. FSuspended := CreateSuspended;
  81. Flags := dtStack_Commited;
  82. if FSuspended then Flags := Flags or dtSuspended;
  83. if DosCreateThread (cardinal (FThreadID), @ThreadProc, pointer (Self),
  84. Flags, 16384) <> 0 then
  85. begin
  86. FFinished := true;
  87. Destroy;
  88. end else FHandle := FThreadID;
  89. IsMultiThread := true;
  90. FFatalException := nil;
  91. }
  92. end;
  93. destructor TThread.Destroy;
  94. begin
  95. if not FFinished and not Suspended then
  96. begin
  97. Terminate;
  98. WaitFor;
  99. end;
  100. {
  101. if FHandle <> -1 then DosKillThread (cardinal (FHandle));
  102. FFatalException.Free;
  103. FFatalException := nil;
  104. inherited Destroy;
  105. RemoveThread (Self);
  106. }
  107. end;
  108. procedure TThread.Resume;
  109. begin
  110. { FSuspended := not (DosResumeThread (cardinal (FHandle)) = 0);}
  111. end;
  112. procedure TThread.Suspend;
  113. begin
  114. { FSuspended := DosSuspendThread (cardinal (FHandle)) = 0;}
  115. end;
  116. procedure TThread.Terminate;
  117. begin
  118. FTerminated := true;
  119. end;
  120. function TThread.WaitFor: Integer;
  121. var
  122. FH: cardinal;
  123. begin
  124. { WaitFor := DosWaitThread (FH, dtWait);}
  125. end;