Skip to content

Commit

Permalink
Merge branch 'init_modules_once'
Browse files Browse the repository at this point in the history
  • Loading branch information
till-s committed Sep 6, 2019
2 parents 4af4d8b + f7d409e commit 8ec37f7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 11 deletions.
5 changes: 5 additions & 0 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Added support for obtaining interface MTU in libTstAux; this
is used by rssi_bridge to fragment larger messages.

Ensure protocol module's modStartup()/modShutdown() are executed
only once (the same module can be used by multiple communication
ports).

R4.1.2:
Removed R4.1.1 tag which had been forced.

Expand Down
4 changes: 2 additions & 2 deletions src/cpsw_comm_addr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void CCommAddressImpl::startProtoStack()
mods.push_back( m );
}
for ( i = mods.size() - 1; i >= 0; i-- ) {
mods[i]->modStartup();
mods[i]->modStartupOnce();
}
}
mtu_ = protoStack_->open()->getMTU();
Expand All @@ -144,7 +144,7 @@ void CCommAddressImpl::shutdownProtoStack()
if ( protoStack_ && running_ ) {
ProtoMod m;
for ( m = protoStack_->getProtoMod(); m; m=m->getUpstreamProtoMod() ) {
m->modShutdown();
m->modShutdownOnce();
}
running_ = false;
}
Expand Down
37 changes: 31 additions & 6 deletions src/cpsw_proto_mod.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ IPortImpl::isOpen() const
// class IOpened;
//
// class IBase {
// shared_ptr<IOpened> open() = 0;
// shared_ptr<IOpened> open() = 0;
// void someBaseFunction() = 0;
// };
//
Expand All @@ -65,7 +65,7 @@ IPortImpl::isOpen() const
//
// (We use this for streaming endpoints. If nobody holds
// the interface 'open' then traffic should be discarded
// instead of clogging the queue and eventually stalling
// instead of clogging the queue and eventually stalling
// RSSI).
//
// How can we have a single class implement both interfaces
Expand All @@ -78,8 +78,8 @@ IPortImpl::isOpen() const
// shared_ptr<Implementation> handle_;
// int openCount_;
// public:
// void someBaseFunction(); // implementation
// void functionOnlyAvailableToOpened(); // implementation
// void someBaseFunction(); // implementation
// void functionOnlyAvailableToOpened(); // implementation
// shared_ptr<IOpened> open();
//
// static shared_ptr<IBase> factory();
Expand Down Expand Up @@ -147,7 +147,7 @@ IPortImpl::isOpen() const
// return retVal;
// }
//
// Remains the 'CloseManager'. This deletor doesn't really
// Remains the 'CloseManager'. This deletor doesn't really
// delete anything but just keeps track of the openCount_
// and resets the handle_ once all 'opened' pointers go away.
//
Expand Down Expand Up @@ -315,7 +315,7 @@ CPortImpl::pushDownstream(BufChain bc, const CTimeout *rel_timeout)
}

if ( rval ) {
// just went offline - drain
// just went offline - drain
while ( ! isOpen() && tryPop() )
;
}
Expand Down Expand Up @@ -388,6 +388,31 @@ CProtoModImpl::CProtoModImpl()
{
}

CProtoModBase::CProtoModBase()
: started_( 0 )
{
}

void
CProtoModBase::modStartupOnce()
{
if ( 0 == started_++ ) {
modStartup();
}
}


void
CProtoModBase::modShutdownOnce()
{
if ( 0 >= started_ ) {
throw InternalError("Protocol Module startup count <= 0");
}
if ( 0 == --started_ ) {
modShutdown();
}
}

void
CProtoModImpl::modStartup()
{
Expand Down
18 changes: 16 additions & 2 deletions src/cpsw_proto_mod.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ class IProtoMod {

virtual void modStartup() = 0;
virtual void modShutdown() = 0;
virtual void modStartupOnce() = 0;
virtual void modShutdownOnce() = 0;

virtual const char *getName() const = 0;

Expand Down Expand Up @@ -410,7 +412,20 @@ class CPortImpl : public IPortImpl {
}
};

class CProtoModImpl : public IProtoMod {
class CProtoModBase : public IProtoMod {
private:
int started_;
public:
CProtoModBase();

// ensure that module's startup/shutdown are
// only executed once (first/last time)
virtual void modStartupOnce();
virtual void modShutdownOnce();

};

class CProtoModImpl : public CProtoModBase {
protected:
ProtoDoor upstream_;

Expand All @@ -422,7 +437,6 @@ class CProtoModImpl : public IProtoMod {
// subclasses may want to start threads
// once the module is attached
virtual void modStartup();

virtual void modShutdown();

virtual void attach(ProtoDoor upstream);
Expand Down
2 changes: 1 addition & 1 deletion src/cpsw_proto_mod_rssi.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class CProtoModRssi;
typedef shared_ptr<CProtoModRssi> ProtoModRssi;

class CProtoModRssi: public CShObj, public IPortImpl, public IProtoMod, public CRssi, public IMTUQuerier {
class CProtoModRssi: public CShObj, public IPortImpl, public CProtoModBase, public CRssi, public IMTUQuerier {
private:
ProtoDoor upstream_;

Expand Down

0 comments on commit 8ec37f7

Please sign in to comment.