microsoft / STL

MSVC's implementation of the C++ Standard Library.
Other
10.19k stars 1.5k forks source link

`xlock.cpp`: Should we use `SRWLOCK` instead of `CRITICAL_SECTION`? #3521

Open frederick-vs-ja opened 1 year ago

frederick-vs-ja commented 1 year ago

In #2317, MSVC STL dropped support for Windows Vista and make SRWLOCK unconditionally used for mutex. However, there're still some implementation details using CRITICAL_SECTION, all of which can be found in xlock.cpp (via xmtx.hpp and xmtx.cpp).

It seems that switching to SRWLOCK doesn't affect ABI (as support for Vista has been dropped). Should we do this?

StephanTLavavej commented 1 year ago

I've taken a look at the code - it should be possible, as there shouldn't be any mix-and-match concerns from user code (as xlock.cpp's state is static). However, it must be done with great care, as the helper functions appear on the export surface. That is, the _Mtxinit family is exported from msvcp140.dll for our eternal nemesis, /clr:pure. It should be possible to continue to export them (marked as unused and preserved for ABI) while xlock.cpp switches to using SRWLOCK.

AlexGuteniev commented 1 year ago

Make sure that none of these mutexes are used as recursive