From 2bd17dfdf493286c4164cdc8accdb056e91e6f3c Mon Sep 17 00:00:00 2001 From: wadman Date: Mon, 10 Jul 2017 17:35:24 +0300 Subject: [PATCH] Small changes Checking Terminated flag before calling some methods. Update .gitignore for lazarus. --- .gitignore | 4 ++++ wcthread.pas | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 19864c6..771050e 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,8 @@ *.a *.o *.ocx +*.bak +*.ppu # Delphi autogenerated files (duplicated info) *.cfg @@ -60,6 +62,8 @@ # Delphi history and backups __history/ __recovery/ +backup/ +lib/ *.~* # Castalia statistics file (since XE7 Castalia is distributed with Delphi) diff --git a/wcthread.pas b/wcthread.pas index 9a5d3f5..2b177ff 100644 --- a/wcthread.pas +++ b/wcthread.pas @@ -496,7 +496,7 @@ procedure TTaskThread.WMTaskStart(var Msg: TThreadMessage); message := _GetMessage(Msg.LParam); param := message^.Parameter; message^.task.DoExecute(message^.Msg, param); - if message^.task.State = tsDestroying then begin + if message^.task.State in [tsRunningDestroy, tsDestroying] then begin message^.task.FState := tsReadyToFree; _FreeMessage(message); end else begin @@ -535,7 +535,7 @@ procedure TTask.DoFinish(const AMsg: Word; const AParameter: Variant); FState := tsFinished; FOnFinish(Self, AMsg, AParameter); end; - if State = tsDestroying then + if State in [tsRunningDestroy, tsDestroying] then FState := tsReadyToFree; end; @@ -546,13 +546,13 @@ function TTask.ItsMe: boolean; procedure TTask.DoProgress(const Msg: Word; const Value: Word); begin - if (State <> tsDestroying) and Assigned(FOnProgress) then + if (not Terminated) and Assigned(FOnProgress) then FOnProgress(Self, Msg, Value); end; procedure TTask.DoMessage(const AMsg: Word; const AParameter: Variant); begin - if (State <> tsDestroying) and Assigned(FOnMessage) then + if (not Terminated) and Assigned(FOnMessage) then FOnMessage(Self, AMsg, AParameter); end; @@ -578,7 +578,7 @@ procedure TTask.PostProgress(const AValue: Word); procedure TTask.PostProgress(const AMsg, AValue: Word); begin - if (State <> tsDestroying) then begin + if (not Terminated) then begin if Assigned(FCaller) then begin FCaller.PostToThreadMessage(WM_TASK_PROGRESS, 0, _NewMessage(nil, Self, AMsg, AValue)); end else begin @@ -589,7 +589,7 @@ procedure TTask.PostProgress(const AMsg, AValue: Word); procedure TTask.PostMessage(const AMsg: Word; const AParameter: Variant); begin - if (State <> tsDestroying) then begin + if (not Terminated) then begin if Assigned(FCaller) then begin FCaller.PostToThreadMessage(WM_TASK_MESSAGE, 0, _NewMessage(nil, Self, AMsg, AParameter)); end else begin @@ -610,10 +610,10 @@ procedure TTask.WaitMs(const Ms: cardinal); procedure TTask.PreDestroy; begin - if FState = tsRunning then - FState := tsRunningDestroy + if FState = tsRunning then + FState := tsRunningDestroy else - FState := tsDestroying; + FState := tsDestroying; FTerminated := true; end; @@ -658,7 +658,7 @@ procedure TTask.Start(const ACaller: TWCThread); procedure TTask.Start(const ACaller: TWCThread; const AMsg: Word; const AParam: Variant); begin - if State = tsDestroying then + if Terminated then raise Exception.CreateFmt('%s cannot start while destroying.', [Name]); FTerminated := false; FCaller := ACaller;