Skip to content

Commit

Permalink
[threads] fixed FPC can not be used for quicklib.Threads issue #106
Browse files Browse the repository at this point in the history
  • Loading branch information
exilon committed Jun 14, 2022
1 parent 7da0314 commit d2e1bf5
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Quick.Threads.pas
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{ ***************************************************************************
Copyright (c) 2016-2021 Kike Pérez
Copyright (c) 2016-2022 Kike Pérez
Unit : Quick.Threads
Description : Thread safe collections
Author : Kike Pérez
Version : 1.5
Created : 09/03/2018
Modified : 08/09/2021
Modified : 14/06/2022
This file is part of QuickLib: https://github.com/exilon/QuickLib
Expand Down Expand Up @@ -152,7 +152,11 @@ TThreadObjectList<T: class> = class(TList<T>)
TSimpleThread = class(TThread)
private
fExecuteProc : TProc;
{$IFNDEF FPC}
fTimeoutFlag : TLightweightEvent;
{$ELSE}
fTimeoutFlag : TSimpleEvent;
{$ENDIF}
public
constructor Create(aProc: TProc; aCreateSuspended, aFreeOnTerminate : Boolean);
destructor Destroy; override;
Expand Down Expand Up @@ -549,6 +553,7 @@ TAsyncTask = class(TInterfacedObject,IAsyncTask)
destructor Destroy; override;
end;

{$IFNDEF FPC}
IAsyncTask<T> = interface
['{8529BBD4-B5AD-4674-8E42-3C74F5156A97}']
function Result : T; overload;
Expand All @@ -567,6 +572,7 @@ TAsyncTask<T> = class(TInterfacedObject,IAsyncTask<T>)
class function Run(const aAction : TFunc<T>) : IAsyncTask<T>; virtual;
destructor Destroy; override;
end;
{$ENDIF}

TBackgroundTasks = class
private
Expand Down Expand Up @@ -2289,7 +2295,7 @@ procedure TAdvThread.DoExecute;
{$ELSE}
if Assigned(fExceptionProc) then fExceptionProc(Exception(AcquireExceptionObject))
{$ENDIF}
else raise e;
else raise;
end;
end;
end;
Expand Down Expand Up @@ -2360,7 +2366,6 @@ class function TRunTask.Execute_Sync(aParamArray: array of const; aOwnedParams:
end;

{ TAsyncTask }

constructor TAsyncTask.Create(aAction : TProc);
begin
fProcess := TSimpleThread.Create(aAction,False,True);
Expand Down Expand Up @@ -2389,6 +2394,7 @@ procedure TAsyncTask.Wait;

{ TAsyncTask<T> }

{$IFNDEF FPC}
constructor TAsyncTask<T>.Create(aAction: TFunc<T>);
begin
fWaitForResult := False;
Expand Down Expand Up @@ -2424,6 +2430,7 @@ function TAsyncTask<T>.Result(const aTimeout: Cardinal): T;
Result := fTaskResult;
fProcess.Free;
end;
{$ENDIF}

{ TParamValue }

Expand Down Expand Up @@ -2574,11 +2581,14 @@ function TBackgroundWorkers.WaitAndRetryForever(aWaitTimeBetweenRetriesMS: Integ
end;

{ TSimpleThread }

constructor TSimpleThread.Create(aProc: TProc; aCreateSuspended, aFreeOnTerminate : Boolean);
begin
if not Assigned(aProc) then raise EArgumentNilException.Create('param cannot be nil!');
{$IFNDEF FPC}
fTimeoutFlag := TLightweightEvent.Create;
{$ELSE}
fTimeoutFlag := TSimpleEvent.Create;
{$ENDIF}
fTimeoutFlag.ResetEvent;
fExecuteProc := aProc;
inherited Create(aCreateSuspended);
Expand Down

0 comments on commit d2e1bf5

Please sign in to comment.