add complete locking to the ProcDispatcher

on both levels
- the front-end needs locking to ensure consistent state (memory barrier)
- the back-end nees locking to coordinate command processing
This commit is contained in:
Fischlurch 2016-12-14 04:18:58 +01:00
parent 4c30c349aa
commit a853851447
3 changed files with 39 additions and 4 deletions

View file

@ -35,12 +35,15 @@
//using boost::str; //using boost::str;
using backend::ThreadJoinable; using backend::ThreadJoinable;
using lib::Sync;
using lib::RecursiveLock_Waitable;
namespace proc { namespace proc {
namespace control { namespace control {
class DispatcherLoop class DispatcherLoop
: ThreadJoinable : ThreadJoinable
, public Sync<RecursiveLock_Waitable>
{ {
public: public:
DispatcherLoop (Subsys::SigTerm notification) DispatcherLoop (Subsys::SigTerm notification)
@ -93,6 +96,7 @@ namespace control {
bool bool
ProcDispatcher::start (Subsys::SigTerm termNotification) ProcDispatcher::start (Subsys::SigTerm termNotification)
{ {
Lock sync(this);
if (runningLoop_) return false; if (runningLoop_) return false;
runningLoop_.reset ( runningLoop_.reset (
@ -111,6 +115,7 @@ namespace control {
bool bool
ProcDispatcher::isRunning() ProcDispatcher::isRunning()
{ {
Lock sync(this);
return bool(runningLoop_); return bool(runningLoop_);
} }
@ -119,6 +124,7 @@ namespace control {
void void
ProcDispatcher::requestStop() ProcDispatcher::requestStop()
{ {
Lock sync(this);
UNIMPLEMENTED ("trigger shutdown into the dispacher loop thread"); UNIMPLEMENTED ("trigger shutdown into the dispacher loop thread");
} }
@ -127,6 +133,7 @@ namespace control {
void void
ProcDispatcher::activate() ProcDispatcher::activate()
{ {
Lock sync(this);
INFO (command, "Session command processing activated."); ///////////////TODO only emit these log messages when processing is *really* started/stopped INFO (command, "Session command processing activated."); ///////////////TODO only emit these log messages when processing is *really* started/stopped
TODO ("implement command processing queue"); TODO ("implement command processing queue");
} }
@ -135,6 +142,7 @@ namespace control {
void void
ProcDispatcher::deactivate() ProcDispatcher::deactivate()
{ {
Lock sync(this);
INFO (command, "Session command interface closed."); INFO (command, "Session command interface closed.");
TODO ("implement command processing queue"); TODO ("implement command processing queue");
} }
@ -143,6 +151,7 @@ namespace control {
void void
ProcDispatcher::clear() ProcDispatcher::clear()
{ {
Lock sync(this);
if (!empty()) if (!empty())
WARN (command, "DISCARDING pending Session commands."); WARN (command, "DISCARDING pending Session commands.");
TODO ("implement command processing queue"); TODO ("implement command processing queue");
@ -152,6 +161,7 @@ namespace control {
bool bool
ProcDispatcher::empty() const ProcDispatcher::empty() const
{ {
Lock sync(this);
TODO ("implement command processing queue"); TODO ("implement command processing queue");
return true; return true;
} }

View file

@ -38,6 +38,7 @@
//#include "lib/symbol.hpp" //#include "lib/symbol.hpp"
#include "common/subsys.hpp" #include "common/subsys.hpp"
#include "lib/depend.hpp" #include "lib/depend.hpp"
#include "lib/sync.hpp"
#include <memory> #include <memory>
//#include <functional> //#include <functional>
@ -60,6 +61,7 @@ namespace control {
* @todo Type-comment * @todo Type-comment
*/ */
class ProcDispatcher class ProcDispatcher
: public lib::Sync<>
{ {
unique_ptr<DispatcherLoop> runningLoop_; unique_ptr<DispatcherLoop> runningLoop_;

View file

@ -224,11 +224,34 @@
<node CREATED="1481599413419" ID="ID_673133356" MODIFIED="1481599420290" TEXT="Ticket #318"/> <node CREATED="1481599413419" ID="ID_673133356" MODIFIED="1481599420290" TEXT="Ticket #318"/>
<node CREATED="1481599421021" ID="ID_461768132" MODIFIED="1481599492544" TEXT="Locking kl&#xe4;ren"> <node CREATED="1481599421021" ID="ID_461768132" MODIFIED="1481599492544" TEXT="Locking kl&#xe4;ren">
<icon BUILTIN="pencil"/> <icon BUILTIN="pencil"/>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1481599447034" ID="ID_27053080" MODIFIED="1481599486152" TEXT="mu&#xdf; unique_ptr locken"> <node CREATED="1481684383530" ID="ID_236117" MODIFIED="1481684451657" TEXT="zwei unabh&#xe4;ngige Locks">
<icon BUILTIN="flag-yellow"/> <icon BUILTIN="yes"/>
<node CREATED="1481684391921" ID="ID_138369898" MODIFIED="1481684442846" TEXT="Front-End">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
das Lock sorgt hier f&#252;r konsistenten Zustand und Sichtbarkeit (memory barrier)
</p>
</body>
</html>
</richcontent>
</node>
<node CREATED="1481684394544" ID="ID_1314197501" MODIFIED="1481684422640" TEXT="Back-End">
<richcontent TYPE="NOTE"><html>
<head>
</head>
<body>
<p>
Lock ist hier das Dispatcher-Lock
</p>
</body>
</html>
</richcontent>
</node> </node>
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1481599454593" ID="ID_1547594303" MODIFIED="1481599484757" TEXT="mu&#xdf; Operationen auf dem Thread locken">
<icon BUILTIN="flag-yellow"/>
</node> </node>
<node CREATED="1481599468712" ID="ID_1273965744" MODIFIED="1481599482440" TEXT="Vorsicht beim Anhalten (Deadlock-Gefahr)"> <node CREATED="1481599468712" ID="ID_1273965744" MODIFIED="1481599482440" TEXT="Vorsicht beim Anhalten (Deadlock-Gefahr)">
<icon BUILTIN="messagebox_warning"/> <icon BUILTIN="messagebox_warning"/>