Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. { TODO }
  2. { Thread management routines }
  3.  
  4. type
  5.   PRaiseFrame = ^TRaiseFrame;
  6.   TRaiseFrame = record
  7.     NextRaise: PRaiseFrame;
  8.     ExceptAddr: Pointer;
  9.     ExceptObject: TObject;
  10.     ExceptionRecord: pointer; {PExceptionRecord}
  11.   end;
  12.  
  13. var
  14.   ThreadCount: Integer;
  15.  
  16.  
  17. procedure AddThread;
  18. begin
  19.   InterlockedIncrement(ThreadCount);
  20. end;
  21.  
  22. procedure RemoveThread;
  23. begin
  24.   InterlockedDecrement(ThreadCount);
  25. end;
  26.  
  27. constructor TThread.Create(CreateSuspended: Boolean; const StackSize: SizeUInt = DefaultStackSize);
  28. begin
  29.   inherited Create;
  30.   AddThread;
  31.   FSuspended := CreateSuspended;
  32.   {TODO}
  33.   FFatalException := nil;
  34. end;
  35.  
  36. destructor TThread.Destroy;
  37. begin
  38.   if not FFinished and not Suspended then
  39.   begin
  40.     Terminate;
  41.     WaitFor;
  42.   end;
  43.   FFatalException.Free;
  44.   FFatalException := nil;
  45.   inherited Destroy;
  46.   RemoveThread;
  47. end;
  48.  
  49. procedure TThread.CallOnTerminate;
  50. begin
  51.   FOnTerminate(Self);
  52. end;
  53.  
  54. procedure TThread.DoTerminate;
  55. begin
  56.   if Assigned(FOnTerminate) then
  57.     Synchronize(@CallOnTerminate);
  58. end;
  59.  
  60. function TThread.GetPriority: TThreadPriority;
  61. begin
  62.   {TODO}
  63. end;
  64.  
  65. procedure TThread.SetPriority(Value: TThreadPriority);
  66. begin
  67.   {TODO}
  68. end;
  69.  
  70. procedure TThread.SetSuspended(Value: Boolean);
  71. begin
  72.   if Value <> FSuspended then
  73.     if Value then Suspend else Resume;
  74. end;
  75.  
  76. procedure TThread.Suspend;
  77. begin
  78.   FSuspended := True;
  79.   SuspendThread(FHandle);
  80. end;
  81.  
  82. procedure TThread.Resume;
  83. begin
  84.   if ResumeThread(FHandle) = 1 then FSuspended := False;
  85. end;
  86.  
  87. procedure TThread.Terminate;
  88. begin
  89.   FTerminated := True;
  90. end;
  91.  
  92. function TThread.WaitFor: Integer;
  93. begin
  94.   {TODO}
  95. end;
  96.