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

[core] Introduced the CSharedResource #2293

Closed

Conversation

maxsharabayko
Copy link
Collaborator

@maxsharabayko maxsharabayko commented Apr 13, 2022

NB! The description is outdated, as now issue #2234 is being addressed in this PR.

Introducing the CSharedResource class. Not yet used in the code. Potentially the m_ConnectionLock can be converted to the CSharedResource.

@maxsharabayko maxsharabayko added Type: Maintenance Work required to maintain or clean up the code [core] Area: Changes in SRT library core labels Apr 13, 2022
@maxsharabayko maxsharabayko added this to the v1.4.5 milestone Apr 13, 2022
@ethouris
Copy link
Collaborator

A similar thing has been already introduced for the use of group locking - the apiAcquire and apiRelease pair and the scoped wrapper for it GroupKeeper.

This is currently built in into the group, but could be abstracted out for more purposes, and maybe in future it could be also used for sockets in order to prevent any still hanging around risks of deleting a socket being in use in another thread.

@gou4shi1
Copy link
Contributor

gou4shi1 commented Apr 14, 2022

It looks like std::recursive_mutex.
If C++11 is enabled, we can just use std::recursive_mutex?

@ethouris
Copy link
Collaborator

The "shared resource" type is introduced exactly in order to not lock mutexes guarding the container access in order to run some longer procedure on an object contained in this container.

@gou4shi1
Copy link
Contributor

The "shared resource" type is introduced exactly in order to not lock mutexes guarding the container access in order to run some longer procedure on an object contained in this container.

It looks like std::shared_ptr?

@ethouris
Copy link
Collaborator

No. This is for objects potentially being used by multiple threads at a time and at some point they have to be deleted.

@gou4shi1
Copy link
Contributor

No. This is for objects potentially being used by multiple threads at a time and at some point they have to be deleted.

If all users of the shared_ptr (from different threads) end, the resource will be deleted automatically.

@gou4shi1
Copy link
Contributor

gou4shi1 commented Apr 23, 2022

It looks like std::shared_ptr?

For example, m_Sockets could be std::map<SOCKETID, std::shared_ptr<CUDTSocket>>, all other containers only store std::weak_ptr<CUDTSocket> (meaning that they don't hold the longtime ownership of that socket), if some function need a temporary ownership of that socket, it can just use std::weak_ptr<CUDTSocket>::lock(), without need to hold m_GlobControlLock in the whole function to guard the socket existence.

@maxsharabayko maxsharabayko modified the milestones: v1.4.5, Next Release Apr 25, 2022
@maxsharabayko maxsharabayko modified the milestones: v1.5.1, Next release Sep 12, 2022
@maxsharabayko maxsharabayko modified the milestones: v1.5.2, Backlog Dec 12, 2022
@maxsharabayko maxsharabayko modified the milestones: Backlog, v1.5.4 Aug 21, 2024
@maxsharabayko
Copy link
Collaborator Author

Closing as outdated and partially covered by PR #2981 (a SharedMutex class).

@maxsharabayko maxsharabayko deleted the develop/shared_resource branch August 23, 2024 08:51
Copy link

codecov bot commented Aug 23, 2024

Codecov Report

Attention: Patch coverage is 89.83051% with 6 lines in your changes missing coverage. Please review.

Project coverage is 65.93%. Comparing base (1dacc2a) to head (dfe367a).
Report is 410 commits behind head on master.

Files Patch % Lines
srtcore/sync.cpp 85.71% 3 Missing ⚠️
srtcore/sync.h 91.30% 2 Missing ⚠️
srtcore/core.cpp 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2293      +/-   ##
==========================================
+ Coverage   65.67%   65.93%   +0.25%     
==========================================
  Files          95       95              
  Lines       19520    19569      +49     
==========================================
+ Hits        12819    12902      +83     
+ Misses       6701     6667      -34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Type: Maintenance Work required to maintain or clean up the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants