Ignore:
Timestamp:
Nov 29, 2023, 2:35:44 PM (12 months ago)
Author:
chronos
Message:
  • Modified: HighDpi branch updated to trunk version.
File:
1 moved

Legend:

Unmodified
Added
Removed
  • branches/highdpi/Packages/Common/Threading.pas

    r462 r463  
    1 unit UThreading;
    2 
    3 {$mode delphi}
     1unit Threading;
    42
    53interface
    64
    75uses
    8   UDpiControls, Classes, SysUtils, Forms, Contnrs, SyncObjs;
     6  UDpiControls, Classes, SysUtils, Forms, Generics.Collections, SyncObjs;
    97
    108type
    119  TExceptionEvent = procedure (Sender: TObject; E: Exception) of object;
    1210  TMethodCall = procedure of object;
    13 
    1411
    1512  { TVirtualThread }
     
    2219    function GetSuspended: Boolean; virtual; abstract;
    2320    function GetTerminated: Boolean; virtual; abstract;
    24     function GetThreadId: Integer; virtual; abstract;
     21    function GetThreadId: TThreadID; virtual; abstract;
    2522    procedure SetFreeOnTerminate(const AValue: Boolean); virtual; abstract;
    2623    procedure SetPriority(const AValue: TThreadPriority); virtual; abstract;
     
    4239    property Terminated: Boolean read GetTerminated write SetTerminated;
    4340    property Finished: Boolean read GetFinished;
    44     property ThreadId: Integer read GetThreadId;
     41    property ThreadId: TThreadID read GetThreadId;
    4542  end;
    4643
     
    6865    function GetSuspended: Boolean; override;
    6966    function GetTerminated: Boolean; override;
    70     function GetThreadId: Integer; override;
     67    function GetThreadId: TThreadID; override;
    7168    procedure SetFreeOnTerminate(const AValue: Boolean); override;
    7269    procedure SetPriority(const AValue: TThreadPriority); override;
     
    10299  { TThreadList }
    103100
    104   TThreadList = class(TObjectList)
    105     function FindById(Id: Integer): TVirtualThread;
     101  TThreadList = class(TObjectList<TVirtualThread>)
     102    function FindById(Id: TThreadID): TVirtualThread;
    106103    constructor Create; virtual;
    107104  end;
     
    164161  if MainThreadID = ThreadID then Method
    165162  else begin
    166     Thread := ThreadList.FindById(ThreadID);
     163    try
     164      ThreadListLock.Acquire;
     165      Thread := ThreadList.FindById(ThreadID);
     166    finally
     167      ThreadListLock.Release;
     168    end;
    167169    if Assigned(Thread) then begin
    168170      Thread.Synchronize(Method);
     
    173175{ TThreadList }
    174176
    175 function TThreadList.FindById(Id: Integer): TVirtualThread;
     177function TThreadList.FindById(Id: TThreadID): TVirtualThread;
    176178var
    177179  I: Integer;
    178180begin
    179181  I := 0;
    180   while (I < ThreadList.Count) and (TVirtualThread(ThreadList[I]).ThreadID <> Id) do
     182  while (I < ThreadList.Count) and (ThreadList[I].ThreadID <> Id) do
    181183    Inc(I);
    182   if I < ThreadList.Count then Result := TVirtualThread(ThreadList[I])
     184  if I < ThreadList.Count then Result := ThreadList[I]
    183185    else Result := nil;
    184186end;
     
    233235end;
    234236
    235 function TListedThread.GetThreadId: Integer;
     237function TListedThread.GetThreadId: TThreadID;
    236238begin
    237239  Result := FThread.ThreadID;
     
    290292  end;
    291293  FThread.Free;
    292   inherited Destroy;
     294  inherited;
    293295end;
    294296
     
    364366
    365367end.
    366 
Note: See TracChangeset for help on using the changeset viewer.