Skip to content

Commit

Permalink
fine tuning critical section lock
Browse files Browse the repository at this point in the history
  • Loading branch information
zamronypj committed Nov 21, 2021
1 parent 0eccb6c commit ea8688b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 50,6 @@ implementation
StdOutIntf,
ProtocolProcessorIntf,
RunnableIntf,
ThreadSafeProtocolProcessorImpl,
FpwebProcessorImpl,
FpwebStdOutWriterImpl,
ThreadSafeFpwebResponseAwareImpl,
Expand All @@ -75,22 74,13 @@ implementation
end;

fProtocol := TFpwebProcessor.create(
fLock,
fStdOut as IFpwebResponseAware,
svrConfig
);

//TFpwebProcessor also act as server
fServer := fProtocol as IRunnableWithDataNotif;

if svrConfig.threaded then
begin
fProtocol := TThreadSafeProtocolProcessor.create(
fLock,
fProtocol,
fServer,
fServer
);
end;
end;

destructor TFpwebAppServiceProvider.destroy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 15,7 @@ interface

uses

SyncObjs,
RunnableIntf,
RunnableWithDataNotifIntf,
ProtocolProcessorIntf,
Expand All @@ -38,6 39,7 @@ interface
*-----------------------------------------------*)
TFpwebProcessor = class(TInterfacedObject, IProtocolProcessor, IRunnable, IRunnableWithDataNotif)
private
fLock : TCriticalSection;
fStdIn : IStreamAdapter;
fRequestReadyListener : IReadyListener;
fDataListener : IDataAvailListener;
Expand Down Expand Up @@ -75,6 77,7 @@ TFpwebProcessor = class(TInterfacedObject, IProtocolProcessor, IRunnable, IR

public
constructor create(
const lock : TCriticalSection;
const conn : IFpwebResponseAware;
const svrConfig : TFpwebSvrConfig
);
Expand Down Expand Up @@ -179,10 182,12 @@ THttpServerThread = class(TThread)
end;

constructor TFpwebProcessor.create(
const lock : TCriticalSection;
const conn : IFpwebResponseAware;
const svrConfig : TFpwebSvrConfig
);
begin
fLock := lock;
fConnection := conn;
fStdIn := nil;
fRequestReadyListener := nil;
Expand All @@ -198,6 203,7 @@ THttpServerThread = class(TThread)
fRequestReadyListener := nil;
fStdIn := nil;
fConnection := nil;
fLock := nil;
inherited destroy();
end;

Expand Down Expand Up @@ -264,15 270,32 @@ THttpServerThread = class(TThread)
var fpwebEnv : ICGIEnvironment;
begin
fConnection.response := response;
fpwebEnv := buildEnv(request);

fRequestReadyListener.ready(
//we will not use socket stream as we will have our own IStdOut
//that write output with TFpHttpServer
TNullStreamAdapter.create(),
fpwebEnv,
TStreamAdapter.create(TStringStream.create(request.content))
);
if (fSvrConfig.threaded) then
begin
fLock.acquire();
try
fpwebEnv := buildEnv(request);
fRequestReadyListener.ready(
//we will not use socket stream as we will have our own IStdOut
//that write output with TFpHttpServer
TNullStreamAdapter.create(),
fpwebEnv,
TStreamAdapter.create(TStringStream.create(request.content))
);
finally
fLock.release();
end;
end else
begin
fpwebEnv := buildEnv(request);
fRequestReadyListener.ready(
//we will not use socket stream as we will have our own IStdOut
//that write output with TFpHttpServer
TNullStreamAdapter.create(),
fpwebEnv,
TStreamAdapter.create(TStringStream.create(request.content))
);
end;
end;

procedure TFpwebProcessor.handleRequest(
Expand Down

0 comments on commit ea8688b

Please sign in to comment.