Skip to content

Commit

Permalink
[groups] Remove NDEBUG from GroupSession.h (project-chip#16445)
Browse files Browse the repository at this point in the history
* [groups] Remove NDEBUG from GroupSession.h

Using NDEBUG to change public structure layouts is
problematic since it may introduce hard to debug bugs when
integrating the CHIP library with external components that
are built with different compiler options.

* Restyled by whitespace

* Remove ReferenceCounted completely as suggested by the author

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and andrei-menzopol committed Apr 14, 2022
1 parent eac39c2 commit 851873f
Showing 1 changed file with 2 additions and 48 deletions.
50 changes: 2 additions & 48 deletions src/transport/GroupSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,48 +18,20 @@

#include <app/util/basic-types.h>
#include <lib/core/GroupId.h>
#include <lib/core/ReferenceCounted.h>
#include <lib/support/Pool.h>
#include <transport/Session.h>

namespace chip {
namespace Transport {

#ifndef NDEBUG
class GroupSessionDeleter
{
public:
static void Release(IncomingGroupSession * entry) {}
static void Release(OutgoingGroupSession * entry) {}
};
#endif

class IncomingGroupSession : public Session
#ifndef NDEBUG
// The group session is ephemeral, its lifespan is controlled by whoever is using it. To prevent the object being destroyed
// while there are still SessionHandle or SessionHolder pointing to it, we enforce a reference counter check at its destruction
// in debug build.
,
public ReferenceCounted<IncomingGroupSession, GroupSessionDeleter, 0>
#endif
{
public:
IncomingGroupSession(GroupId group, FabricIndex fabricIndex, NodeId sourceNodeId) : mGroupId(group), mSourceNodeId(sourceNodeId)
{
SetFabricIndex(fabricIndex);
}
~IncomingGroupSession() override
{
NotifySessionReleased();
#ifndef NDEBUG
VerifyOrDie(GetReferenceCount() == 0);
#endif
}

#ifndef NDEBUG
void Retain() override { ReferenceCounted<IncomingGroupSession, GroupSessionDeleter, 0>::Retain(); }
void Release() override { ReferenceCounted<IncomingGroupSession, GroupSessionDeleter, 0>::Release(); }
#endif
~IncomingGroupSession() override { NotifySessionReleased(); }

Session::SessionType GetSessionType() const override { return Session::SessionType::kGroupIncoming; }
#if CHIP_PROGRESS_LOGGING
Expand Down Expand Up @@ -102,31 +74,13 @@ class IncomingGroupSession : public Session
};

class OutgoingGroupSession : public Session
#ifndef NDEBUG
// The group session is ephemeral, its lifespan is controlled by whoever is using it. To prevent the object being destroyed
// while there are still SessionHandle or SessionHolder pointing to it, we enforce a reference counter check at its destruction
// in debug build.
,
public ReferenceCounted<OutgoingGroupSession, GroupSessionDeleter, 0>
#endif
{
public:
OutgoingGroupSession(GroupId group, FabricIndex fabricIndex, NodeId sourceNodeId) : mGroupId(group), mSourceNodeId(sourceNodeId)
{
SetFabricIndex(fabricIndex);
}
~OutgoingGroupSession() override
{
NotifySessionReleased();
#ifndef NDEBUG
VerifyOrDie(GetReferenceCount() == 0);
#endif
}

#ifndef NDEBUG
void Retain() override { ReferenceCounted<OutgoingGroupSession, GroupSessionDeleter, 0>::Retain(); }
void Release() override { ReferenceCounted<OutgoingGroupSession, GroupSessionDeleter, 0>::Release(); }
#endif
~OutgoingGroupSession() override { NotifySessionReleased(); }

Session::SessionType GetSessionType() const override { return Session::SessionType::kGroupOutgoing; }
#if CHIP_PROGRESS_LOGGING
Expand Down

0 comments on commit 851873f

Please sign in to comment.