-
Notifications
You must be signed in to change notification settings - Fork 906
Automatic call of startup() and cleanup() #3098 #3109
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
Conversation
|
Ok, there are two general problems with this thing:
C++ guarantees the order of initialization only within the frames of one source file, but not between files, and this actually causes problems if you provide a library (meaning, global constructors for objects provided by the application may be called prior to those provided by the library). A potential risk exists, for example, if some application is going to create a socket in one of its global constructors. We can blame the application, if the caller hasn't called |
|
Thank you for your feedback! Here’s my response to both points:
|
|
Alright, then I understand that this first change can be added independently on the second one, so this one better go to the other PR. That would be cleaner. |
|
I’ve decided not to create a separate pull request for the packet filter changes. These modifications are not entirely independent, as they rely on the existing codebase, which means the pull requests would need to be applied in a specific order. Additionally, the updates to the packet filter are justified within the context of the overall changes in this pull request. |
|
Regarding the packet filter changes, I’ve simply encapsulated the global variables ( This allows us to:
|
|
My latest push aligns In the end, this pull request maintains the same overall logic as before, with the key difference that it now correctly fixes issue #3098. |
| @@ -462,6 +462,9 @@ class CUDTUnited | |||
|
|
|||
| CUDTSocket* locateAcquireSocket(SRTSOCKET u, ErrorHandling erh = ERH_RETURN); | |||
| bool acquireSocket(CUDTSocket* s); | |||
| bool startGarbageCollector(); | |||
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.
If these functions require m_InitLock to be locked, please add appropriate TSA annotation.
Co-authored-by: Sektor van Skijlen <ethouris@gmail.com>
This pull request fixes issue #3098 by ensuring that startup() and cleanup() are called automatically. As a result, there is no longer a need to call them implicitly when creating the first socket.
Additionally, the garbage collector thread now starts only when the first socket is created. Some refactoring has been done, providing an opportunity to stop this thread after the last socket is closed, but no implementation has been added for this yet.
Finally, this pull request introduces a separate packet filter factory, decoupled from CUDTUnited, to prevent the “Static Initialization Order Fiasco.”