Skip to content

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
Checking Terminated flag before calling some methods.
Update .gitignore for lazarus.
  • Loading branch information
wadman committed Jul 10, 2017
1 parent 0fba6b1 commit 2bd17df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -44,6 +44,8 @@
*.a
*.o
*.ocx
*.bak
*.ppu

# Delphi autogenerated files (duplicated info)
*.cfg
Expand All @@ -60,6 +62,8 @@
# Delphi history and backups
__history/
__recovery/
backup/
lib/
*.~*

# Castalia statistics file (since XE7 Castalia is distributed with Delphi)
Expand Down
20 changes: 10 additions & 10 deletions wcthread.pas
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 2bd17df

Please sign in to comment.