-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Addition of SessionSharedPtr
#18539
Addition of SessionSharedPtr
#18539
Conversation
de33323
to
101900c
Compare
PR #18539: Size comparison from a777a80 to 101900c Increases above 0.2%:
Increases (31 builds for cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, telink)
Full report (31 builds for cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, telink)
|
101900c
to
63a2208
Compare
{ | ||
public: | ||
SessionSharedPtr() {} | ||
SessionSharedPtr(Transport::Session & session) { mSession.Emplace(session); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no naked session object around, the only usage of this function is called by the constructor of SessionHandle
we should make this API protected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had some difficutly writing unit tests whenever we have too strict of friend class coupling.
I believe APIs/classes should be able to function as a stand alone without demanding fried class usage.
/* | ||
* Assume shared ownership of the provided session. | ||
*/ | ||
void Grab(Transport::Session & session) { mSession.Emplace(session); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no naked session object around, the only usage of this function is inside PairingSession
to hold the unauthenticated session, where it is grabbing a SessionHandle
.
void Grab(const Transport::Session & SessionHandle)
* | ||
* Since this is a strong reference, this should be short-lived and only used as a stack variable. | ||
*/ | ||
class SessionHandle : protected SessionSharedPtr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SessionHandle
and SessionSharedPtr
are basically same thing exposing different API. SessionHandle
is immutable, SessionSharedPtr
is mutable. Instead of let SessionHandle
derive from SessionSharedPtr
, I suggest we do it in the opposite way, use Optional<SessionHandle>
as a field of SessionSharedPtr
.
In such implemetation, the SessionHandle is a word smaller, and all APIs of SessionSharedPtr
should target SessionHandle
not naked session.
The only problem is that SessionHandle
is should be copy-able by SessionSharedPtr
, which we can resolve by using a private copy constructor and a friend declare.
The goal of this class is not non-copyable, but prevent from creating this object in heap, to ensure that the object is ephemeral. Generally C++ can't do that, it is just a coding convention.
Transport::Session * operator->() const { return Get(); } | ||
|
||
protected: | ||
Transport::Session * Get() const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be private.
Add operator==(const SessionSharedPtr &)
API, to help implementing SessionHandle::operator==
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
This stale pull request has been automatically closed. Thank you for your contributions. |
Problem
SessionHolder
is used both as a strong, shared_ptr like smart-ptr object (it has ref-counting) as well as a weak_ptr like object (the underlying reference can be removed by SessionManager when evicting a session).This is confusing and makes it incongruous with similar smart-ptr constructs in STL.
Solution
Creates a new
SessionSharedPtr
as per #18399 that now plays the part of a strong, shared_ptr like construct. This sets the stage for us to pivotSessionHolder
to a pure, weak_ptr like construct.Entities like
PairingSession
,DeviceController
that need to momentarily own a session while it is being setup are already pivoting to using aSessionSharedPtr
like model in #18397.Once this PR merges, we can fully shift them over.