Explorar o código

[threads] fixed FPC can not be used for quicklib.Threads issue #106

Exilon %!s(int64=3) %!d(string=hai) anos
pai
achega
d2e1bf56fb
Modificáronse 1 ficheiros con 15 adicións e 5 borrados
  1. 15 5
      Quick.Threads.pas

+ 15 - 5
Quick.Threads.pas

@@ -1,13 +1,13 @@
 { ***************************************************************************
 { ***************************************************************************
 
 
-  Copyright (c) 2016-2021 Kike Pérez
+  Copyright (c) 2016-2022 Kike Pérez
 
 
   Unit        : Quick.Threads
   Unit        : Quick.Threads
   Description : Thread safe collections
   Description : Thread safe collections
   Author      : Kike Pérez
   Author      : Kike Pérez
   Version     : 1.5
   Version     : 1.5
   Created     : 09/03/2018
   Created     : 09/03/2018
-  Modified    : 08/09/2021
+  Modified    : 14/06/2022
 
 
   This file is part of QuickLib: https://github.com/exilon/QuickLib
   This file is part of QuickLib: https://github.com/exilon/QuickLib
 
 
@@ -152,7 +152,11 @@ type
   TSimpleThread = class(TThread)
   TSimpleThread = class(TThread)
   private
   private
     fExecuteProc : TProc;
     fExecuteProc : TProc;
+    {$IFNDEF FPC}
     fTimeoutFlag : TLightweightEvent;
     fTimeoutFlag : TLightweightEvent;
+    {$ELSE}
+    fTimeoutFlag : TSimpleEvent;
+    {$ENDIF}
   public
   public
     constructor Create(aProc: TProc; aCreateSuspended, aFreeOnTerminate : Boolean);
     constructor Create(aProc: TProc; aCreateSuspended, aFreeOnTerminate : Boolean);
     destructor Destroy; override;
     destructor Destroy; override;
@@ -549,6 +553,7 @@ type
     destructor Destroy; override;
     destructor Destroy; override;
   end;
   end;
 
 
+  {$IFNDEF FPC}
   IAsyncTask<T> = interface
   IAsyncTask<T> = interface
   ['{8529BBD4-B5AD-4674-8E42-3C74F5156A97}']
   ['{8529BBD4-B5AD-4674-8E42-3C74F5156A97}']
     function Result : T; overload;
     function Result : T; overload;
@@ -567,6 +572,7 @@ type
     class function Run(const aAction : TFunc<T>) : IAsyncTask<T>; virtual;
     class function Run(const aAction : TFunc<T>) : IAsyncTask<T>; virtual;
     destructor Destroy; override;
     destructor Destroy; override;
   end;
   end;
+  {$ENDIF}
 
 
   TBackgroundTasks = class
   TBackgroundTasks = class
   private
   private
@@ -2289,7 +2295,7 @@ begin
       {$ELSE}
       {$ELSE}
       if Assigned(fExceptionProc) then fExceptionProc(Exception(AcquireExceptionObject))
       if Assigned(fExceptionProc) then fExceptionProc(Exception(AcquireExceptionObject))
       {$ENDIF}
       {$ENDIF}
-        else raise e;
+        else raise;
     end;
     end;
   end;
   end;
 end;
 end;
@@ -2360,7 +2366,6 @@ begin
 end;
 end;
 
 
 { TAsyncTask }
 { TAsyncTask }
-
 constructor TAsyncTask.Create(aAction : TProc);
 constructor TAsyncTask.Create(aAction : TProc);
 begin
 begin
   fProcess := TSimpleThread.Create(aAction,False,True);
   fProcess := TSimpleThread.Create(aAction,False,True);
@@ -2389,6 +2394,7 @@ end;
 
 
 { TAsyncTask<T> }
 { TAsyncTask<T> }
 
 
+{$IFNDEF FPC}
 constructor TAsyncTask<T>.Create(aAction: TFunc<T>);
 constructor TAsyncTask<T>.Create(aAction: TFunc<T>);
 begin
 begin
   fWaitForResult := False;
   fWaitForResult := False;
@@ -2424,6 +2430,7 @@ begin
   Result := fTaskResult;
   Result := fTaskResult;
   fProcess.Free;
   fProcess.Free;
 end;
 end;
+{$ENDIF}
 
 
 { TParamValue }
 { TParamValue }
 
 
@@ -2574,11 +2581,14 @@ begin
 end;
 end;
 
 
 { TSimpleThread }
 { TSimpleThread }
-
 constructor TSimpleThread.Create(aProc: TProc; aCreateSuspended, aFreeOnTerminate : Boolean);
 constructor TSimpleThread.Create(aProc: TProc; aCreateSuspended, aFreeOnTerminate : Boolean);
 begin
 begin
   if not Assigned(aProc) then raise EArgumentNilException.Create('param cannot be nil!');
   if not Assigned(aProc) then raise EArgumentNilException.Create('param cannot be nil!');
+  {$IFNDEF FPC}
   fTimeoutFlag := TLightweightEvent.Create;
   fTimeoutFlag := TLightweightEvent.Create;
+  {$ELSE}
+  fTimeoutFlag := TSimpleEvent.Create;
+  {$ENDIF}
   fTimeoutFlag.ResetEvent;
   fTimeoutFlag.ResetEvent;
   fExecuteProc := aProc;
   fExecuteProc := aProc;
   inherited Create(aCreateSuspended);
   inherited Create(aCreateSuspended);