win7: load synch functions on demand #143598
Open
+28
−73
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.
Currently, for Windows 7 only, we do a fun thing with pre-main initialisers to optimistically load some functions (used for
park
/unpark
) which require Windows 8+. This means they're loaded even if unused and can mildly affect start up times (albeit not by much). More of an issue is that someone else's pre-main initialiser could run before our own (we've taken steps to mitigated that but it is just a mitigation). Also the code isn't tested by us (i.e. rust CI) any more so it's prone to bit rot. In any case, failure may not be noticed because if it does fail then the Windows 7 code will be used instead.This PR changes it to load on demand instead. In the happy case this just means doing one load and two equality checks. In the sad case where we've not yet attempted to load the module, this will be slower. But it's a one time cost, usually taken in
park
(which is "slow" on account of waiting an indefinite period of time).We could alternatively just use the Windows 7 synchronisation functions exclusively. The issue with that is they're undocumented and technically could be changed or removed at any point, albeit compatibility guarantees make this somewhat unlikely. Still, we should try to be well behaved.