Skip to content

Commit

Permalink
clean up anon ref to executor ASAP
Browse files Browse the repository at this point in the history
A reference to an anonymous method executor in IOmniTask is cleaned up as soon as possible. This allows OTL tasks to be executed from a package. 
[fixes #132]
  • Loading branch information
gabr42 committed Mar 22, 2019
1 parent d7819f8 commit 577c93b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
18 changes: 12 additions & 6 deletions OtlTaskControl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@
/// Blog : http://thedelphigeek.com
/// Contributors : GJ, Lee_Nover, Sean B. Durkin
/// Creation date : 2008-06-12
/// Last modification : 2018-12-13
/// Version : 1.40b
/// Last modification : 2019-03-22
/// Version : 1.40c
///</para><para>
/// History:
/// 1.40c: 2019-03-22
/// - [sglienke] TOmniTaskExecutor.Cleanup clears reference to anonymous function executor.
/// This allows tasks to be run from a package. [issue #132]
/// 1.40b: 2018-12-13
/// - Fixed: If additional wait objects registered with RegisterWaitObject were
/// constantly signalled, timers were never called.
Expand Down Expand Up @@ -829,9 +832,9 @@ TOmniMessageInfo = record
procedure GetMethodAddrAndSignature(const methodName: string;
var methodAddress: pointer; var methodSignature: TOmniInvokeType);
procedure GetMethodNameFromInternalMessage(const msg: TOmniMessage; var msgName: string;
var msgData: TOmniValue {$IFDEF OTL_Anonymous}; var func:
TOmniTaskControlInvokeFunction; var funcEx: TOmniTaskControlInvokeFunctionEx; var proc:
TProc<integer>; var taskFunc: TOmniTaskInvokeFunction {$ENDIF OTL_Anonymous});
var msgData: TOmniValue {$IFDEF OTL_Anonymous};
var func: TOmniTaskControlInvokeFunction; var funcEx: TOmniTaskControlInvokeFunctionEx;
var proc: TProc<integer>; var taskFunc: TOmniTaskInvokeFunction {$ENDIF OTL_Anonymous});
function GetOptions: TOmniTaskControlOptions;
function HaveElapsedTimer: boolean;
procedure Initialize;
Expand Down Expand Up @@ -1726,7 +1729,7 @@ procedure TOmniTask.Terminate;
if not otExecuting then
otTerminateWillCallExecute := true;
finally otCleanupLock.ExitWriteLock; end;
// TODO 1 -oPrimoz Gabrijelcic : This is very suspicious :(

if otTerminateWillCallExecute then //call Execute to run at least cleanup code
InternalExecute(true);
end; { TOmniTask.Terminate }
Expand Down Expand Up @@ -2129,6 +2132,9 @@ procedure TOmniTaskExecutor.Cleanup;
begin
oteWorkerIntf := nil;
FreeAndNil(oteTimers);
{$IFDEF OTL_Anonymous}
oteFunc := nil;
{$ENDIF OTL_Anonymous}
end; { TOmniTaskExecutor.Cleanup }

procedure TOmniTaskExecutor.DispatchCommMessage(newMsgHandle: TOmniTransitionEvent;
Expand Down
5 changes: 5 additions & 0 deletions history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

- New features:
- [Jacek Laskowski] donated a new OTL icon (res\OTL.ico).

- Bug fixes:
- [sglienke] A reference to an anonymous method executor in IOmniTask is
cleaned up as soon as possible. This allows OTL tasks to be executed
from a package. [issue #132]

3.07.7: 2019-02-23

Expand Down

0 comments on commit 577c93b

Please # to comment.