better control of the shutdown sequence

holding the SessionCommandService in a unique_ptr allows us to
close the Interface reliably *before* the Loop is halted.
This commit is contained in:
Fischlurch 2016-12-15 05:54:48 +01:00
parent a3c22b8aff
commit 86f446c197
3 changed files with 63 additions and 7 deletions

View file

@ -33,12 +33,13 @@
//#include "proc/mobject/mobject.hpp"
//#include "proc/mobject/placement.hpp"
//#include <boost/format.hpp>
#include <memory>
//using boost::str;
using backend::ThreadJoinable;
using lib::Sync;
using lib::RecursiveLock_Waitable;
using std::unique_ptr;
namespace proc {
namespace control {
@ -51,22 +52,27 @@ namespace control {
bool canDispatch_{false};
bool blocked_ {false};
SessionCommandService commandService_;
unique_ptr<SessionCommandService> commandService_;
public:
DispatcherLoop (Subsys::SigTerm notification)
: ThreadJoinable("Lumiera Session"
, bind (&DispatcherLoop::run, this, notification))
, commandService_(*this)
, commandService_(new SessionCommandService(*this))
{
INFO (session, "Proc-Dispatcher running...");
}
~DispatcherLoop()
{
this->join();
INFO (session, "Proc-Dispatcher stopped.");
try {
Lock sync(this);
commandService_.reset();
this->join();
INFO (session, "Proc-Dispatcher stopped.");
}
ERROR_LOG_AND_IGNORE(session, "Stopping the Proc-Dispatcher");
}
void

View file

@ -6371,12 +6371,18 @@ And last but not least: the difficult part of this whole concept is encapsulated
{{red{WIP ... draft}}}</pre>
</div>
<div title="SessionSubsystem" creator="Ichthyostega" modifier="Ichthyostega" created="201612150347" modified="201612150359" tags="def impl SessionLogic img" changecount="8">
<div title="SessionSubsystem" creator="Ichthyostega" modifier="Ichthyostega" created="201612150347" modified="201612150453" tags="def impl SessionLogic img" changecount="9">
<pre>//A subsystem within Proc-Layer, responsible for lifecycle and access to the editing [[Session]].//
[img[Structure of the Session Subsystem|uml/Session-subsystem.png]]
!Structure
The ProcDispatcher is at the heart of the //Session Subsystem.// Because the official interface for working on the session, the {{{SessionCommand}}} façade, is expressed in terms of sending command messages to invoke predefined [[commands|CommandHandling]] to operate on the SessionInterface, the actual implementation of such a {{{SessionCommandService}}} needs a component actually to enqueue and dispatch those commands -- which is the {{{DispatcherLoop}}} within the ProcDispatcher. As usual, the ''lifecycle'' is controlled by a subsystem descriptor, which starts and stopps the whole subsystem; and this starting and stopping in turn translates into starting/stopping of the dispatcher loop. On the other hand, //activation of the dispatcher,// which means actively to dispatch commands, is controlled by the lifecycle of the session proper. The latter is just a data structure, and can be loaded / saved and rebuilt through the ''session manager''.</pre>
The ProcDispatcher is at the heart of the //Session Subsystem.// Because the official interface for working on the session, the {{{SessionCommand}}} façade, is expressed in terms of sending command messages to invoke predefined [[commands|CommandHandling]] to operate on the SessionInterface, the actual implementation of such a {{{SessionCommandService}}} needs a component actually to enqueue and dispatch those commands -- which is the {{{DispatcherLoop}}} within the ProcDispatcher. As usual, the ''lifecycle'' is controlled by a subsystem descriptor, which starts and stopps the whole subsystem; and this starting and stopping in turn translates into starting/stopping of the dispatcher loop. On the other hand, //activation of the dispatcher,// which means actively to dispatch commands, is controlled by the lifecycle of the session proper. The latter is just a data structure, and can be loaded / saved and rebuilt through the ''session manager''.
!Lifecycle
!!!shutdown
Shutdown is initiated by sending a message to the dispatcher loop. {{red{TODO 12/2016}}} need to ensure the loop terminates reliably then! When loop terminates, the {{{sigTerm}}} of the SessionSubsystem is invoked, which then in turn causes the DispatcherLoop thread to be reaped.
</pre>
</div>
<div title="SideBarOptions" modifier="CehTeh" created="200706200048">
<pre>&lt;&lt;search&gt;&gt;&lt;&lt;closeAll&gt;&gt;&lt;&lt;permaview&gt;&gt;&lt;&lt;newTiddler&gt;&gt;&lt;&lt;saveChanges&gt;&gt;&lt;&lt;slider chkSliderOptionsPanel OptionsPanel &quot;options »&quot; &quot;Change TiddlyWiki advanced options&quot;&gt;&gt;</pre>

View file

@ -507,6 +507,30 @@
<node CREATED="1481769144226" ID="ID_1609251574" MODIFIED="1481769153389" TEXT="mu&#xdf; Service-API extrahieren">
<icon BUILTIN="pencil"/>
</node>
<node CREATED="1481777039358" ID="ID_395609084" MODIFIED="1481777050096" TEXT="Shutdown sauber regeln">
<node CREATED="1481777054755" ID="ID_1551225439" MODIFIED="1481777106485">
<richcontent TYPE="NODE"><html>
<head>
</head>
<body>
<p>
mu&#223; SessionCommandService schlie&#223;en
</p>
<p>
<i>bevor</i>&#160;die Dispatcher-loop angehalten wird
</p>
</body>
</html>
</richcontent>
</node>
<node CREATED="1481777114203" ID="ID_1156396729" MODIFIED="1481777121886" TEXT="Lock, um Deadlock zu vermeitden"/>
<node CREATED="1481777122306" ID="ID_1506554988" MODIFIED="1481777133445" TEXT="alles im dtor -&gt; noexcept"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1481777210447" ID="ID_1392452935" MODIFIED="1481777289370" TEXT="TODO: sicherstellen da&#xdf; join nicht blockt">
<arrowlink COLOR="#5a97df" DESTINATION="ID_1789585729" ENDARROW="Default" ENDINCLINATION="8475;0;" ID="Arrow_ID_1930701586" STARTARROW="None" STARTINCLINATION="8475;0;"/>
<icon BUILTIN="flag-yellow"/>
</node>
</node>
</node>
<node CREATED="1481510244184" ID="ID_1521406724" MODIFIED="1481510260635" TEXT="kann dann in CoreService einfach &#xfc;ber die .facade() zugreifen">
<icon BUILTIN="idea"/>
@ -10965,6 +10989,26 @@
<node CREATED="1481688529539" ID="ID_1972961763" MODIFIED="1481688540109" TEXT="SessionManager ist zust&#xe4;ndig"/>
<node CREATED="1481688544921" ID="ID_1934560784" MODIFIED="1481688561386" TEXT="wenn Session geladen, ist ProcDispatcher freigegeben"/>
<node CREATED="1481688562830" ID="ID_708961458" MODIFIED="1481688582024" TEXT="SessionSubsystem startet processing loop im ProcDispatcher"/>
<node CREATED="1481777252497" ID="ID_1789585729" MODIFIED="1481777279294" TEXT="Shutdown">
<linktarget COLOR="#5a97df" DESTINATION="ID_1789585729" ENDARROW="Default" ENDINCLINATION="8475;0;" ID="Arrow_ID_1930701586" SOURCE="ID_1392452935" STARTARROW="None" STARTINCLINATION="8475;0;"/>
<node CREATED="1481777297635" ID="ID_483368010" MODIFIED="1481777305432" TEXT="Deadlock-Gefahr">
<icon BUILTIN="messagebox_warning"/>
</node>
<node CREATED="1481777308978" ID="ID_1380229085" MODIFIED="1481777327818" TEXT="Lebensdauer der Session-Datenstruktur">
<node CREATED="1481777328479" ID="ID_1668359018" MODIFIED="1481777336447" TEXT="unabh&#xe4;ngig vom Session-Subsystem">
<icon BUILTIN="messagebox_warning"/>
</node>
<node CREATED="1481777343548" ID="ID_354877994" MODIFIED="1481777350704" TEXT="irgendwann post main()"/>
</node>
<node CREATED="1481777355747" ID="ID_1804595708" MODIFIED="1481777364326" TEXT="Subsystem-&gt;end">
<node CREATED="1481777368330" ID="ID_1933237483" MODIFIED="1481777374277" TEXT="Halte-Nachricht"/>
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1481777374801" ID="ID_1844558240" MODIFIED="1481777385577" TEXT="sicherstellen, da&#xdf; Loop anh&#xe4;lt">
<icon BUILTIN="flag-pink"/>
</node>
<node CREATED="1481777397542" ID="ID_1147135932" MODIFIED="1481777409960" TEXT="DispatcherLoop tot"/>
<node CREATED="1481777410972" ID="ID_457965735" MODIFIED="1481777418982" TEXT="sigTerm"/>
</node>
</node>
</node>
</node>
<node CREATED="1448314932726" ID="ID_669869188" MODIFIED="1448314941137" POSITION="right" TEXT="Render"/>