<condition_variable>: Avoid squirrelly forward declaration of _Cnd_internal_imp_t
#4545
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.
Followup to #4457 (comment). I performed this as a series of well-structured commits.
Commits
primitives.hpp: Include__msvc_threads_core.hpp.This will allow us to move the definition of
_Cnd_internal_imp_tinto__msvc_threads_core.hpp.This is a safe transformation because only 3 files include
primitives.hppand they already drag in__msvc_threads_core.hpp(sharedmutex.cppdirectly;cond.cppandmutex.cppviaxthreads.h).In
_Cnd_internal_imp_t, rename its_Aligned_storage_tdata membercvto_Cv_storage.This will allow us to move the definition into
stl/inc/__msvc_threads_core.hpp.The new name is consistent with how
_Mtx_internal_imp_tnames its_Aligned_storage_tdata member_Cs_storage.Change definition:
_Cnd_internal_imp_t::_get_cv=>Concurrency::details::_Get_cond_varChange the member function
_Cnd_internal_imp_t::_get_cvinto the non-member functionConcurrency::details::_Get_cond_var, renamed to be more descriptive.Drop the unnecessary comment
// get pointer to implementation.Now we don't need to qualify
stl_condition_variable_win7, defined immediately above.We need to take a parameter
::_Cnd_internal_imp_t* _Cond, qualified for clarity.We need
inlinefor the non-member function.Replace calls:
cond->_get_cv()=>Concurrency::details::_Get_cond_var(cond)Move the definition of
_Cnd_internal_imp_tfromprimitives.hppto__msvc_threads_core.hpp.This is still within
extern "C".Change
std::=>_STD.We no longer need the wacky
/clrforward declaration workaround.Directly store
_Cnd_internal_imp_t _Cnd_storage.We can do this because its only data member is exactly
_Aligned_storage_t<_Cnd_internal_imp_size, _Cnd_internal_imp_alignment>, so the representation is unchanged.Then we can simplify the
_Mycnd()member function.This follows the same pattern as
_Mutex_base's_Mtx_internal_imp_t _Mtx_storageand_Mymtx().Move
_Cnd_internal_imp_size/_Cnd_internal_imp_alignmentwithin_Cnd_internal_imp_t.This changes
_INLINE_VARtostatic.The comment
// Size and alignment for _Cnd_internal_imp_tis now unnecessary and can be dropped.Fuse
_Critical_section_alignand_Cnd_internal_imp_alignmentinto their only uses.Follow
_Cnd_internal_imp_t's simpler pattern in_Mtx_internal_imp_t.This expresses "16 or 8 bytes" as
2 * sizeof(void*).Note
After this, I believe that we should apply a similar bugfix as #4294, checking
UNDOCKED_WINDOWS_UCRTwhen determining_Cnd_internal_imp_size, but I'm not doing that here (mixing functional changes with cleanups is bad).