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

Addition of SessionSharedPtr #18539

Closed

Conversation

mrjerryjohns
Copy link
Contributor

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 pivot SessionHolder 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 a SessionSharedPtr like model in #18397.

Once this PR merges, we can fully shift them over.

@github-actions
Copy link

github-actions bot commented May 18, 2022

PR #18539: Size comparison from a777a80 to 101900c

Increases above 0.2%:

platform target config section a777a80 101900c change % change
efr32 lighting-app BRD4161A (read only) 914908 917308 2400 0.3
.text 914900 917300 2400 0.3
BRD4161A+rpc (read only) 949096 951480 2384 0.3
.text 949088 951472 2384 0.3
BRD4161A+rs911x (read only) 788388 790756 2368 0.3
.text 788380 790748 2368 0.3
window-app BRD4161A (read only) 895028 897428 2400 0.3
.text 895020 897420 2400 0.3
linux tv-casting-app debug (read only) 5412689 5430305 17616 0.3
.text 4714338 4731826 17488 0.4
Increases (31 builds for cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, telink)
platform target config section a777a80 101900c change % change
cyw30739 light cyw930739m2evb_01 (read/write) 624974 625598 624 0.1
.app_xip_area 528588 529212 624 0.1
lock cyw930739m2evb_01 (read/write) 628018 628666 648 0.1
.app_xip_area 533088 533736 648 0.1
ota-requestor-no-progress-logging cyw930739m2evb_01 (read/write) 572474 573122 648 0.1
.app_xip_area 467828 468476 648 0.1
efr32 lighting-app BRD4161A (read only) 914908 917308 2400 0.3
.text 914900 917300 2400 0.3
BRD4161A+rpc (read only) 949096 951480 2384 0.3
.text 949088 951472 2384 0.3
BRD4161A+rs911x (read only) 788388 790756 2368 0.3
.text 788380 790748 2368 0.3
lock-app BRD4161A+wf200 (read only) 946640 947296 656 0.1
.text 946632 947288 656 0.1
window-app BRD4161A (read only) 895028 897428 2400 0.3
.text 895020 897420 2400 0.3
esp32 all-clusters-app c3devkit (read only) 1000736 1001330 594 0.1
.flash.text 1000736 1001330 594 0.1
m5stack (read only) 1055679 1056335 656 0.1
.flash.text 1050295 1050951 656 0.1
k32w light k32w061+release (read/write) 682748 683372 624 0.1
.text 598804 599428 624 0.1
lock k32w061+release (read/write) 729228 729868 640 0.1
.text 644892 645532 640 0.1
linux all-clusters-app debug (read only) 2748449 2749073 624 0.0
.rodata 238813 238941 128 0.1
.text 2333330 2333826 496 0.0
bridge-app debug+rpc (read only) 2030385 2031041 656 0.0
.rodata 167305 167465 160 0.1
.text 1704882 1705378 496 0.0
chip-tool debug (read only) 9308237 9315885 7648 0.1
.rodata 480501 480629 128 0.0
.text 7496581 7504101 7520 0.1
chip-tool-no-interactive-ipv6only arm64 (read only) 9079508 9080964 1456 0.0
.text 7166708 7168164 1456 0.0
lighting-app debug+rpc (read only) 2324945 2325569 624 0.0
.rodata 186377 186505 128 0.1
.text 1971138 1971634 496 0.0
lock-app debug (read only) 2238353 2238993 640 0.0
.rodata 196889 197017 128 0.1
.text 1880354 1880866 512 0.0
ota-provider-app debug (read only) 2058873 2059545 672 0.0
.rodata 177184 177344 160 0.1
.text 1723074 1723586 512 0.0
ota-requestor-app debug (read only) 2088193 2088881 688 0.0
.rodata 173376 173504 128 0.1
.text 1754738 1755298 560 0.0
shell debug (read only) 2564321 2565057 736 0.0
.rodata 219986 220210 224 0.1
.text 2181410 2181922 512 0.0
thermostat-no-ble arm64 (read only) 2352044 2352572 528 0.0
.text 1975104 1975632 528 0.0
tv-app debug (read only) 2850537 2851257 720 0.0
.rodata 219665 219761 96 0.0
.text 2447378 2448002 624 0.0
tv-casting-app debug (read only) 5412689 5430305 17616 0.3
.rodata 337825 337953 128 0.0
.text 4714338 4731826 17488 0.4
mbed lock-app CY8CPROTO_062_4343W+release (read/write) 2420288 2420928 640 0.0
.text 1382932 1383572 640 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read/write) 1180611 1181347 736 0.1
text 810400 811144 744 0.1
p6 all-clusters-app default (read/write) 2536128 2538544 2416 0.1
.text 1494392 1496808 2416 0.2
light-app default (read/write) 2422760 2425048 2288 0.1
.text 1381024 1383312 2288 0.2
lock-app default (read/write) 2433408 2435728 2320 0.1
.text 1391672 1393992 2320 0.2
telink light-switch-app tlsr9518adk80d (read/write) 782388 783076 688 0.1
text 553284 553970 686 0.1
lighting-app tlsr9518adk80d (read/write) 802480 803160 680 0.1
text 570050 570734 684 0.1
Full report (31 builds for cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, p6, telink)
platform target config section a777a80 101900c change % change
cyw30739 light cyw930739m2evb_01 (read/write) 624974 625598 624 0.1
.app_xip_area 528588 529212 624 0.1
.bss 79028 79028 0 0.0
.data 708 708 0 0.0
.rodata 0 0 0 0.0
.text 0 0 0 0.0
lock cyw930739m2evb_01 (read/write) 628018 628666 648 0.1
.app_xip_area 533088 533736 648 0.1
.bss 77604 77604 0 0.0
.data 672 672 0 0.0
.rodata 0 0 0 0.0
.text 0 0 0 0.0
ota-requestor-no-progress-logging cyw930739m2evb_01 (read/write) 572474 573122 648 0.1
.app_xip_area 467828 468476 648 0.1
.bss 87024 87024 0 0.0
.data 584 584 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
efr32 lighting-app BRD4161A (read only) 914908 917308 2400 0.3
(read/write) 133244 133244 0 0.0
.bss 131184 131184 0 0.0
.data 2060 2060 0 0.0
.text 914900 917300 2400 0.3
BRD4161A+rpc (read only) 949096 951480 2384 0.3
(read/write) 149928 149928 0 0.0
.bss 147664 147664 0 0.0
.data 2264 2264 0 0.0
.text 949088 951472 2384 0.3
BRD4161A+rs911x (read only) 788388 790756 2368 0.3
(read/write) 129512 129512 0 0.0
.bss 127444 127444 0 0.0
.data 2068 2068 0 0.0
.text 788380 790748 2368 0.3
lock-app BRD4161A+wf200 (read only) 946640 947296 656 0.1
(read/write) 123996 123996 0 0.0
.bss 121972 121972 0 0.0
.data 2024 2024 0 0.0
.text 946632 947288 656 0.1
window-app BRD4161A (read only) 895028 897428 2400 0.3
(read/write) 133304 133304 0 0.0
.bss 131256 131256 0 0.0
.data 2048 2048 0 0.0
.text 895020 897420 2400 0.3
esp32 all-clusters-app c3devkit (read only) 1000736 1001330 594 0.1
(read/write) 1477874 1477874 0 0.0
.dram0.bss 68200 68200 0 0.0
.dram0.data 14608 14608 0 0.0
.flash.rodata 209632 209632 0 0.0
.flash.text 1000736 1001330 594 0.1
.iram0.text 62954 62954 0 0.0
m5stack (read only) 1055679 1056335 656 0.1
(read/write) 479888 479888 0 0.0
.dram0.bss 73728 73728 0 0.0
.dram0.data 34184 34184 0 0.0
.flash.rodata 239980 239980 0 0.0
.flash.text 1050295 1050951 656 0.1
.iram0.text 123267 123267 0 0.0
k32w light k32w061+release (read/write) 682748 683372 624 0.1
.bss 80224 80224 0 0.0
.data 2016 2016 0 0.0
.text 598804 599428 624 0.1
lock k32w061+release (read/write) 729228 729868 640 0.1
.bss 80656 80656 0 0.0
.data 1976 1976 0 0.0
.text 644892 645532 640 0.1
linux all-clusters-app debug (read only) 2748449 2749073 624 0.0
(read/write) 175872 175872 0 0.0
.bss 85056 85056 0 0.0
.data 2064 2064 0 0.0
.data.rel.ro 82584 82584 0 0.0
.dynamic 608 608 0 0.0
.got 4496 4496 0 0.0
.init 27 27 0 0.0
.init_array 1016 1016 0 0.0
.rodata 238813 238941 128 0.1
.text 2333330 2333826 496 0.0
bridge-app debug+rpc (read only) 2030385 2031041 656 0.0
(read/write) 147736 147736 0 0.0
.bss 72832 72832 0 0.0
.data 3936 3936 0 0.0
.data.rel.ro 65384 65384 0 0.0
.dynamic 592 592 0 0.0
.got 4272 4272 0 0.0
.init 27 27 0 0.0
.init_array 688 688 0 0.0
.rodata 167305 167465 160 0.1
.text 1704882 1705378 496 0.0
chip-tool debug (read only) 9308237 9315885 7648 0.1
(read/write) 580976 580976 0 0.0
.bss 23936 23936 0 0.0
.data 1152 1152 0 0.0
.data.rel.ro 549600 549600 0 0.0
.dynamic 624 624 0 0.0
.got 5000 5000 0 0.0
.init 27 27 0 0.0
.init_array 648 648 0 0.0
.rodata 480501 480629 128 0.0
.text 7496581 7504101 7520 0.1
chip-tool-no-interactive-ipv6only arm64 (read only) 9079508 9080964 1456 0.0
(read/write) 647105 647105 0 0.0
.bss 42209 42209 0 0.0
.data 1192 1192 0 0.0
.data.rel.ro 584840 584840 0 0.0
.dynamic 560 560 0 0.0
.got 15016 15016 0 0.0
.init 24 24 0 0.0
.init_array 184 184 0 0.0
.rodata 446484 446484 0 0.0
.text 7166708 7168164 1456 0.0
lighting-app debug+rpc (read only) 2324945 2325569 624 0.0
(read/write) 153184 153184 0 0.0
.bss 74624 74624 0 0.0
.data 2048 2048 0 0.0
.data.rel.ro 70744 70744 0 0.0
.dynamic 608 608 0 0.0
.got 4344 4344 0 0.0
.init 27 27 0 0.0
.init_array 792 792 0 0.0
.rodata 186377 186505 128 0.1
.text 1971138 1971634 496 0.0
lock-app debug (read only) 2238353 2238993 640 0.0
(read/write) 147864 147864 0 0.0
.bss 73312 73312 0 0.0
.data 1568 1568 0 0.0
.data.rel.ro 67272 67272 0 0.0
.dynamic 592 592 0 0.0
.got 4336 4336 0 0.0
.init 27 27 0 0.0
.init_array 752 752 0 0.0
.rodata 196889 197017 128 0.1
.text 1880354 1880866 512 0.0
ota-provider-app debug (read only) 2058873 2059545 672 0.0
(read/write) 140944 140944 0 0.0
.bss 72768 72768 0 0.0
.data 1768 1768 0 0.0
.data.rel.ro 60616 60616 0 0.0
.dynamic 608 608 0 0.0
.got 4504 4504 0 0.0
.init 27 27 0 0.0
.init_array 648 648 0 0.0
.rodata 177184 177344 160 0.1
.text 1723074 1723586 512 0.0
ota-requestor-app debug (read only) 2088193 2088881 688 0.0
(read/write) 143720 143720 0 0.0
.bss 73440 73440 0 0.0
.data 1992 1992 0 0.0
.data.rel.ro 62648 62648 0 0.0
.dynamic 592 592 0 0.0
.got 4344 4344 0 0.0
.init 27 27 0 0.0
.init_array 672 672 0 0.0
.rodata 173376 173504 128 0.1
.text 1754738 1755298 560 0.0
shell debug (read only) 2564321 2565057 736 0.0
(read/write) 199768 199768 0 0.0
.bss 115752 115752 0 0.0
.data 1376 1376 0 0.0
.data.rel.ro 76872 76872 0 0.0
.dynamic 608 608 0 0.0
.got 4192 4192 0 0.0
.init 27 27 0 0.0
.init_array 936 936 0 0.0
.rodata 219986 220210 224 0.1
.text 2181410 2181922 512 0.0
thermostat-no-ble arm64 (read only) 2352044 2352572 528 0.0
(read/write) 176289 176289 0 0.0
.bss 87585 87585 0 0.0
.data 1520 1520 0 0.0
.data.rel.ro 79384 79384 0 0.0
.dynamic 560 560 0 0.0
.got 4768 4768 0 0.0
.init 24 24 0 0.0
.init_array 376 376 0 0.0
.rodata 146924 146924 0 0.0
.text 1975104 1975632 528 0.0
tv-app debug (read only) 2850537 2851257 720 0.0
(read/write) 278720 278720 0 0.0
.bss 190712 190712 0 0.0
.data 4672 4672 0 0.0
.data.rel.ro 77080 77080 0 0.0
.dynamic 592 592 0 0.0
.got 4720 4720 0 0.0
.init 27 27 0 0.0
.init_array 928 928 0 0.0
.rodata 219665 219761 96 0.0
.text 2447378 2448002 624 0.0
tv-casting-app debug (read only) 5412689 5430305 17616 0.3
(read/write) 224992 224992 0 0.0
.bss 78328 78328 0 0.0
.data 2368 2368 0 0.0
.data.rel.ro 138072 138072 0 0.0
.dynamic 608 608 0 0.0
.got 4728 4728 0 0.0
.init 27 27 0 0.0
.init_array 864 864 0 0.0
.rodata 337825 337953 128 0.0
.text 4714338 4731826 17488 0.4
mbed lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2420288 2420928 640 0.0
.bss 202668 202668 0 0.0
.data 5872 5872 0 0.0
.text 1382932 1383572 640 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read/write) 1180611 1181347 736 0.1
bss 138372 138372 0 0.0
rodata 152956 152956 0 0.0
text 810400 811144 744 0.1
p6 all-clusters-app default (read/write) 2536128 2538544 2416 0.1
.bss 136168 136168 0 0.0
.data 2808 2808 0 0.0
.text 1494392 1496808 2416 0.2
light-app default (read/write) 2422760 2425048 2288 0.1
.bss 129488 129488 0 0.0
.data 2608 2608 0 0.0
.text 1381024 1383312 2288 0.2
lock-app default (read/write) 2433408 2435728 2320 0.1
.bss 129304 129304 0 0.0
.data 2568 2568 0 0.0
.text 1391672 1393992 2320 0.2
telink light-switch-app tlsr9518adk80d (read/write) 782388 783076 688 0.1
bss 70608 70608 0 0.0
noinit 40416 40416 0 0.0
text 553284 553970 686 0.1
lighting-app tlsr9518adk80d (read/write) 802480 803160 680 0.1
bss 70864 70864 0 0.0
noinit 40416 40416 0 0.0
text 570050 570734 684 0.1

{
public:
SessionSharedPtr() {}
SessionSharedPtr(Transport::Session & session) { mSession.Emplace(session); }
Copy link
Contributor

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.

Copy link
Contributor

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); }
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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==

@stale
Copy link

stale bot commented Jun 3, 2022

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.

@stale stale bot added the stale Stale issue or PR label Jun 3, 2022
@stale
Copy link

stale bot commented Jun 11, 2022

This stale pull request has been automatically closed. Thank you for your contributions.

@stale stale bot closed this Jun 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants