Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kisspeace committed Feb 4, 2023
1 parent c016d97 commit 0a447c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 101 deletions.
5 changes: 0 additions & 5 deletions source/YDW.FMX.ImageWithURL.ImageViewer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ constructor TImageWithUrlViewer.Create(AOwner: TComponent);

{$IFNDEF ANDROID}
FZoomFactor := 0.001;
FMoveFactor := 1.85;
{$ELSE}
FMoveFactor := 1.85;
FZoomFactor := 0.005;
{$ENDIF}

Expand Down Expand Up @@ -280,7 +278,6 @@ procedure TImageWithUrlViewer.DoZoom(AValue: Integer);
procedure TImageWithUrlViewer.FinishMove;
begin
Self.FNeedToMove := False;
// Self.Cursor := crHandPoint;
end;

procedure TImageWithUrlViewer.FitHeight;
Expand Down Expand Up @@ -336,7 +333,6 @@ procedure TImageWithUrlViewer.MouseDown(Button: TMouseButton; Shift: TShiftState
X, Y: Single);
begin
inherited;
// Self.Cursor := crSQLWait;
FMovePoint := TPointF.Create(X, Y);
FNeedToMove := True;
end;
Expand Down Expand Up @@ -379,7 +375,6 @@ procedure TImageWithUrlViewer.MouseUp(Button: TMouseButton; Shift: TShiftState;
inherited;
FinishMove;
end;
//{$ENDIF}

procedure TImageWithUrlViewer.MouseWheel(Shift: TShiftState; WheelDelta: Integer;
var Handled: Boolean);
Expand Down
109 changes: 13 additions & 96 deletions source/YDW.Threading.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
interface
uses
System.SysUtils, System.Generics.Collections,
IoUtils, System.Classes, System.Generics.Defaults, System.SysConst,
YDW.Debug, System.SyncObjs;
System.Classes, System.SyncObjs, YDW.Debug;

type

Expand Down Expand Up @@ -69,7 +68,6 @@ TThreadAndValue<T> = record
FQueue: TList<T>;
FRunning: TThreadAndValueList;
FWaitList: TThreadList;
// FGarbage: TObjectList<TObject>;
function NewSubThread(AValue: T): TSubWorkerThread;
function QueueCondition: boolean; virtual;
function AutoRestartCondition: boolean; virtual;
Expand Down Expand Up @@ -131,7 +129,7 @@ procedure TGenericYDWQueuedThread<T>.Execute;
if ( not Self.QueueCondition ) then
break;

LItem := TThreadAndValue<T>.Create(FQueue.First); // get next Value from queue
LItem := TThreadAndValue<T>.Create(FQueue.First); { get next Value from queue }
LNewThread := NewSubThread(LItem.Value);
LItem.Thread := LNewThread;
FRunning.Add(LItem);
Expand Down Expand Up @@ -163,43 +161,9 @@ procedure TGenericYDWQueuedThread<T>.Execute;
var LThread := FRunning[I].Thread;

LThread.Terminate;

// if (not LThread.Started) and Self.OnWaitList(LThread) then begin
// FRunning[I].Thread.Free;
// var LUpdatedItem := TThreadAndValue<T>.Create(FRunning[I].Value);
// LUpdatedItem.Thread := nil;
// FRunning[I] := LUpdatedItem;
// end;

end;

{ -- May have issues block begin ! -- }
// var LThPos: integer := FRunning.Count - 1;
// var LTargetPos: integer;
//
// while TRUE do begin
//
// LTargetPos := -1;
//
// if (LThPos < 0) or (FRunning.Count < 1) then
// break;
//
// for I := LThPos downto 0 do begin
// if not Assigned(FRunning[I].Thread) then begin
// LTargetPos := I;
// break;
// end;
// end;
//
// if LTargetPos <> -1 then begin
// FRunning.Delete(LTargetPos);
// Dec(LThPos);
// end else
// Break;
//
// end;
{ -- block end. -- }

finally
FLock.EndWrite();
end;
Expand All @@ -218,20 +182,6 @@ procedure TGenericYDWQueuedThread<T>.Execute;
FWaitList.UnlockList;
end;
end;

{$IFDEF YDW_DEBUG} try {$ENDIF}
// FLock.BeginWrite;
// try
// FGarbage.Clear;
// finally
// FLock.EndWrite;
// end;
{$IFDEF YDW_DEBUG} except
On E: Exception do begin
YDW.Debug.Log('TGenericYDWQueuedThread<T>.Execute(FGarbage.Clear)', E);
raise E;
end;
end; {$ENDIF}

end;
until not AutoRestartCondition;
Expand All @@ -244,16 +194,6 @@ procedure TGenericYDWQueuedThread<T>.Execute;
end;
end;

//procedure TGenericYDWQueuedThread<T>.GarbageAdd(AItem: TObject);
//begin
// FLock.BeginWrite;
// try
// FGarbage.Add(AItem);
// finally
// FLock.EndWrite;
// end;
//end;

function TGenericYDWQueuedThread<T>.GetThreadByItem(
AValue: T): TSubWorkerThread;
var
Expand Down Expand Up @@ -289,9 +229,6 @@ function TGenericYDWQueuedThread<T>.NewSubThread(AValue: T): TSubWorkerThread;
Result.Owner := Self;
Result.Value := AValue;
Result.FreeOnTerminate := False;
// {$IFDEF DEBUG}
// Result.NameThreadForDebugging('YDW-Sub');
// {$ENDIF}
end;

function TGenericYDWQueuedThread<T>.RunningCount: integer;
Expand Down Expand Up @@ -413,9 +350,6 @@ procedure TYdwReusableThread.UnlockedStart;
FThread := TWorkerThread.Create(True);
FThread.Owner := Self;
FThread.FreeOnTerminate := False;
// {$IFDEF YDW_DEBUG}
// FThread.NameThreadForDebugging('YDW-Top');
// {$ENDIF}
FThread.Start;

While not FThread.Started do
Expand Down Expand Up @@ -480,7 +414,6 @@ constructor TGenericYDWQueuedThread<T>.Create;
FThreadsCount := DEFAULT_THREADS_COUNT;
FWaitList := TThreadList.Create;
FWaitList.Duplicates := dupAccept;
// FGarbage := TObjectList<TObject>.Create;
end;

destructor TGenericYDWQueuedThread<T>.Destroy;
Expand All @@ -489,7 +422,6 @@ destructor TGenericYDWQueuedThread<T>.Destroy;
FQueue.Free;
FRunning.Free;
FWaitList.Free;
// FGarbage.Free;
end;

procedure TGenericYDWQueuedThread<T>.OnSubThreadFinish;
Expand Down Expand Up @@ -526,29 +458,15 @@ function TGenericYDWQueuedThread<T>.QueueCondition: boolean;
Result := FQueue.Count > 0;
end;

//function TGenericYDWQueuedThread<T>.RunningIndexByThread(
// const AThread: TThread): integer;
//var
// I: integer;
//begin
// for I := 0 to FRunning.Count - 1 do begin
// if ( FRunning[I].Thread.ThreadID = AThread.ThreadId ) then begin
// Result := I;
// exit;
// end;
// end;
// Result := -1;
//end;


{ TObjectYDWQueuedThreadComponent<T> }

function TGenericYDWQueuedThreadObject<T>.RunningIndex(AValue: T): integer;
var
I: integer;
begin
for I := 0 to FRunning.Count - 1 do begin
if ( AValue = FRunning[I].value ) then begin
if ( AValue = FRunning[I].value ) then
begin
Result := I;
exit;
end;
Expand All @@ -563,7 +481,8 @@ function TGenericYDWQueuedThreadInterface<T>.RunningIndex(AValue: T): integer;
I: integer;
begin
for I := 0 to FRunning.Count - 1 do begin
if ((AValue as TObject) = (FRunning[I].value as TObject )) then begin
if ((AValue as TObject) = (FRunning[I].value as TObject )) then
begin
Result := I;
exit;
end;
Expand All @@ -586,30 +505,28 @@ procedure TGenericYDWQueuedThread<T>.TSubWorkerThread.Execute;
TempItem: TThreadAndValue<T>;
begin
try
// Try
Owner.SubThreadExecute(Value);
// except
// On E: Exception do
// End;
Owner.SubThreadExecute(Value);

finally
Owner.FLock.BeginWrite();
try
LastIndex := Owner.FRunning.Count - 1;

for I := 0 to LastIndex do begin
if ( Owner.FRunning[I].Thread = TThread.Current ) then begin
if ( Owner.FRunning[I].Thread = TThread.Current ) then
begin
ThreadIndex := I;
Break;
end;
end;

if ( ThreadIndex <> LastIndex ) and ( Owner.FRunning.Count > 1 ) then begin
if ( ThreadIndex <> LastIndex ) and ( Owner.FRunning.Count > 1 ) then
begin
Owner.FRunning.Exchange(LastIndex, ThreadIndex);
// FRunning[ThreadIndex] := FRunning[LastIndex];
end;

Owner.FRunning.Delete(LastIndex);
// Owner.FGarbage.Add(Self);

finally
Owner.FLock.EndWrite();
end;
Expand Down

0 comments on commit 0a447c8

Please sign in to comment.