Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inet/(TCP/UDP)Endpoints: Migrate from SystemPool to BitMapObjectPool #11428

Merged
merged 2 commits into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Remove atomic
  • Loading branch information
kghost committed Nov 5, 2021
commit b3aa27eb4348d1936cf6801aa9620c94906dd524
7 changes: 0 additions & 7 deletions src/inet/TCPEndPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2748,13 +2748,6 @@ CHIP_ERROR TCPEndPoint::DoClose(CHIP_ERROR err, bool suppressCallback)
}

// Decrement the ref count that was added when the connection started (in Connect()) or listening started (in Listen()).
//
// When using LwIP, post a callback to Release() rather than calling it directly. Since up-calls
// from LwIP are delivered as events (via the LwIP* methods), we must ensure that all events have been
// cleared from the queue before the end point gets freed, otherwise we'll end up accessing freed memory.
// We achieve this by first preventing further up-calls from LwIP (via the call to tcp_abort() above)
// and then queuing the Release() call to happen after all existing events have been processed.
//
if (oldState != State::kReady && oldState != State::kBound)
{
Release();
Expand Down
2 changes: 1 addition & 1 deletion src/inet/TCPEndPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TCPEndPointDeletor
* endpoints (SOCK_STREAM sockets on Linux and BSD-derived systems) or LwIP
* TCP protocol control blocks, as the system is configured accordingly.
*/
class DLL_EXPORT TCPEndPoint : public EndPointBasis, public AtomicReferenceCounted<TCPEndPoint, TCPEndPointDeletor>
class DLL_EXPORT TCPEndPoint : public EndPointBasis, public ReferenceCounted<TCPEndPoint, TCPEndPointDeletor>
{
friend class InetLayer;
friend class ::chip::Transport::TCPTest;
Expand Down
2 changes: 1 addition & 1 deletion src/inet/UDPEndPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class UDPEndPointDeletor
* endpoints (SOCK_DGRAM sockets on Linux and BSD-derived systems) or LwIP
* UDP protocol control blocks, as the system is configured accordingly.
*/
class DLL_EXPORT UDPEndPoint : public EndPointBasis, public AtomicReferenceCounted<UDPEndPoint, UDPEndPointDeletor>
class DLL_EXPORT UDPEndPoint : public EndPointBasis, public ReferenceCounted<UDPEndPoint, UDPEndPointDeletor>
{
public:
UDPEndPoint() = default;
Expand Down
42 changes: 0 additions & 42 deletions src/lib/core/ReferenceCounted.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,46 +81,4 @@ class ReferenceCounted
count_type mRefCount = kInitRefCount;
};

/// An variant of ReferenceCounted, with atomic counter.
template <class Subclass, class Deletor = DeleteDeletor<Subclass>, int kInitRefCount = 1>
class AtomicReferenceCounted
{
public:
using count_type = uint32_t;

AtomicReferenceCounted() : mRefCount(kInitRefCount) {}

/** Adds one to the usage count of this class */
Subclass * Retain()
{
if (mRefCount == std::numeric_limits<count_type>::max())
{
abort();
}
++mRefCount;

return static_cast<Subclass *>(this);
}

/** Release usage of this class */
void Release()
{
if (mRefCount == 0)
{
abort();
}

if (--mRefCount == 0)
{
Deletor::Release(static_cast<Subclass *>(this));
}
}

/** Get the current reference counter value */
count_type GetReferenceCount() const { return mRefCount.load(); }

private:
std::atomic<count_type> mRefCount;
};

} // namespace chip