Skip to content

Commit

Permalink
let TBlockingProcess inherit from TSynEvent
Browse files Browse the repository at this point in the history
- which is lighter and faster than TEvent on POSIX
  • Loading branch information
Arnaud Bouchez committed Dec 20, 2022
1 parent a5ff70b commit fa7ee86
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/core/mormot.core.threads.pas
Expand Up @@ -815,12 +815,12 @@ TSynBackgroundTimer = class(TSynBackgroundThreadProcess)
// - used e.g. by TBlockingCallback in mormot.rest.server.pas
// - once created, process would block via a WaitFor call, which would be
// released when NotifyFinished is called by the process background thread
TBlockingProcess = class(TEvent)
TBlockingProcess = class(TSynEvent)
protected
fTimeOutMs: integer;
fEvent: TBlockingEvent;
fSafe: PSynLocker;
fOwnedSafe: boolean;
fSafe: PSynLocker;
procedure ResetInternal; virtual; // override to reset associated params
public
/// initialize the semaphore instance
Expand Down Expand Up @@ -2665,7 +2665,7 @@ function TSynBackgroundTimer.Disable(

constructor TBlockingProcess.Create(aTimeOutMs: integer; aSafe: PSynLocker);
begin
inherited Create(nil, false, false, '');
inherited Create; // TSynEvent.Create
if aTimeOutMs <= 0 then
fTimeOutMs := 3000
else // never wait for ever
Expand All @@ -2681,7 +2681,7 @@ constructor TBlockingProcess.Create(aTimeOutMs: integer);

destructor TBlockingProcess.Destroy;
begin
inherited Destroy;
inherited Destroy; // TSynEvent
if fOwnedSafe then
fSafe^.DoneAndFreeMem;
end;
Expand All @@ -2697,7 +2697,7 @@ function TBlockingProcess.WaitFor: TBlockingEvent;
finally
fSafe^.UnLock;
end;
inherited WaitFor(fTimeOutMs);
inherited WaitFor(fTimeOutMs); // TSynEvent
fSafe^.Lock;
try
if fEvent <> evRaised then
Expand Down Expand Up @@ -2726,16 +2726,16 @@ function TBlockingProcess.NotifyFinished(alreadyLocked: boolean): boolean;
if fEvent in [evRaised, evTimeOut] then
exit; // ignore if already notified
fEvent := evRaised;
SetEvent; // notify caller to unlock "WaitFor" method
result := true;
finally
fSafe^.UnLock;
end;
SetEvent; // notify caller to unlock "WaitFor" method outside of fSafe^.Lock
end;

procedure TBlockingProcess.ResetInternal;
begin
ResetEvent;
ResetEvent; // non-blocking TSynEvent method
fEvent := evNone;
end;

Expand Down
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
@@ -1 +1 @@
'2.0.4479'
'2.0.4480'

0 comments on commit fa7ee86

Please sign in to comment.