winapi: Run fls_init in startup thread, before regular constructors #497
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This, together with XboxDev/nxdk-pdclib#48, fixes the issue where constructors were run before thread-local storage was available by running them from the main thread instead of the startup thread. However,
fls_init
is a special constructor that needs to run before any thread creation, so this introduces and uses a new mechanism which allows for constructors to run in the startup thread instead by putting function pointers in a custom subsection of.CRT
(the same thing is done automatically by the compiler for regular constructors).This code can be used to verify that the change works. Before the changes, this would crash during the construction of the global
std::stringstream s
, but with the changes, it should run correctly.Fixes #496.
This will be combined with a submodule update and turned into a normal PR when XboxDev/nxdk-pdclib#48 is merged.