From f0dfbb5d266db9d4fb37fd4dd18de86772606803 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Thu, 2 Mar 2023 08:04:51 -0800 Subject: [PATCH 1/4] _Xtime_diff_to_millis is unused. (No redist impact, still exported.) --- stl/inc/xtimec.h | 1 - stl/src/xtime.cpp | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/xtimec.h b/stl/inc/xtimec.h index 64741469db9..12419359719 100644 --- a/stl/inc/xtimec.h +++ b/stl/inc/xtimec.h @@ -27,7 +27,6 @@ struct xtime { // store time with nanosecond resolution _CRTIMP2_PURE int __cdecl xtime_get(xtime*, int); -_CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis(const xtime*); _CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis2(const xtime*, const xtime*); _CRTIMP2_PURE long long __cdecl _Xtime_get_ticks(); diff --git a/stl/src/xtime.cpp b/stl/src/xtime.cpp index 1f7109b76f1..cc1c5c5c111 100644 --- a/stl/src/xtime.cpp +++ b/stl/src/xtime.cpp @@ -65,6 +65,7 @@ _CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis2(const xtime* xt1, const xtime* return static_cast(diff.sec * _Msec_per_sec + (diff.nsec + _Nsec_per_msec - 1) / _Nsec_per_msec); } +// TRANSITION, ABI: preserved for binary compatibility _CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis(const xtime* xt) { // convert time to milliseconds xtime now; xtime_get(&now, TIME_UTC); From 076fb929aa5abf68bbc9d1eea3ea3e76d0a9c1f7 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 3 Mar 2023 04:35:04 -0800 Subject: [PATCH 2/4] Simplify thread::detach(), part 1: _Check_C_return() is used only once. --- stl/inc/thread | 7 ++++++- stl/inc/xthreads.h | 8 -------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/stl/inc/thread b/stl/inc/thread index 70cd8fb6e6c..6bb594cba36 100644 --- a/stl/inc/thread +++ b/stl/inc/thread @@ -137,7 +137,12 @@ public: _Throw_Cpp_error(_INVALID_ARGUMENT); } - _Check_C_return(_Thrd_detach(_Thr)); + const int _Res = _Thrd_detach(_Thr); + + if (_Res != _Thrd_success) { + _Throw_C_error(_Res); + } + _Thr = {}; } diff --git a/stl/inc/xthreads.h b/stl/inc/xthreads.h index 81576850978..57e9cb340e5 100644 --- a/stl/inc/xthreads.h +++ b/stl/inc/xthreads.h @@ -131,14 +131,6 @@ enum { // constants for error codes extern "C++" [[noreturn]] _CRTIMP2_PURE void __cdecl _Throw_C_error(int _Code); extern "C++" [[noreturn]] _CRTIMP2_PURE void __cdecl _Throw_Cpp_error(int _Code); - -inline int _Check_C_return(int _Res) { // throw exception on failure - if (_Res != _Thrd_success) { - _Throw_C_error(_Res); - } - - return _Res; -} _STD_END #pragma pop_macro("new") _STL_RESTORE_CLANG_WARNINGS From 0372d8aff95c54897e9482834c0efee8e66508c0 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 3 Mar 2023 04:39:53 -0800 Subject: [PATCH 3/4] Simplify thread::detach(), part 2. _Thrd_detach() returns either _Thrd_success or _Thrd_error. _Throw_C_error() translates that to _Throw_Cpp_error(_INVALID_ARGUMENT). --- stl/inc/thread | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/stl/inc/thread b/stl/inc/thread index 6bb594cba36..18f862c5ff3 100644 --- a/stl/inc/thread +++ b/stl/inc/thread @@ -137,10 +137,8 @@ public: _Throw_Cpp_error(_INVALID_ARGUMENT); } - const int _Res = _Thrd_detach(_Thr); - - if (_Res != _Thrd_success) { - _Throw_C_error(_Res); + if (_Thrd_detach(_Thr) != _Thrd_success) { + _Throw_Cpp_error(_INVALID_ARGUMENT); } _Thr = {}; From b5f6d70eb75bda86f714d3f0074af476a01596eb Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 3 Mar 2023 04:56:49 -0800 Subject: [PATCH 4/4] Simplify threads, part 3. _Cnd_timedwait() returns only _Thrd_success or _Thrd_timedout, allowing us to simplify later code. After this, _Throw_C_error() is unused. (No redist impact, still exported.) We don't need the `extern "C++"` from the declaration in stl/inc/xthreads.h - that's for Standard Library Modules, but stl/src/thread0.cpp is always built classically. --- stl/inc/condition_variable | 17 +++-------------- stl/inc/mutex | 8 +++----- stl/inc/xthreads.h | 1 - stl/src/thread0.cpp | 1 + 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/stl/inc/condition_variable b/stl/inc/condition_variable index e4304da8d1a..e5b917a87c0 100644 --- a/stl/inc/condition_variable +++ b/stl/inc/condition_variable @@ -224,16 +224,8 @@ public: // but unfortunately our ABI speaks struct xtime, which is relative to the system clock. _CSTD xtime _Tgt; (void) _To_xtime_10_day_clamped(_Tgt, _Rel_time); - const int _Res = _Cnd_timedwait(_Mycnd(), _Myptr->_Mymtx(), &_Tgt); + (void) _Cnd_timedwait(_Mycnd(), _Myptr->_Mymtx(), &_Tgt); _Guard_unlocks_before_locking_outer.unlock(); - - switch (_Res) { - case _Thrd_timedout: - case _Thrd_success: - break; - default: - _Throw_C_error(_Res); - } } // relock return _Pred(); @@ -262,13 +254,10 @@ private: const int _Res = _Cnd_timedwait(_Mycnd(), _Ptr->_Mymtx(), _Abs_time); _Guard.unlock(); - switch (_Res) { - case _Thrd_success: + if (_Res == _Thrd_success) { return cv_status::no_timeout; - case _Thrd_timedout: + } else { return cv_status::timeout; - default: - _Throw_C_error(_Res); } } }; diff --git a/stl/inc/mutex b/stl/inc/mutex index 46a75447559..393d9dff2c5 100644 --- a/stl/inc/mutex +++ b/stl/inc/mutex @@ -746,13 +746,11 @@ public: // Nothing to do to comply with LWG-2135 because std::mutex lock/unlock are nothrow const int _Res = _Cnd_timedwait(_Mycnd(), _Lck.mutex()->_Mymtx(), _Abs_time); - switch (_Res) { - case _Thrd_success: + + if (_Res == _Thrd_success) { return cv_status::no_timeout; - case _Thrd_timedout: + } else { return cv_status::timeout; - default: - _Throw_C_error(_Res); } } diff --git a/stl/inc/xthreads.h b/stl/inc/xthreads.h index 57e9cb340e5..83c04c3fb50 100644 --- a/stl/inc/xthreads.h +++ b/stl/inc/xthreads.h @@ -129,7 +129,6 @@ enum { // constants for error codes _RESOURCE_UNAVAILABLE_TRY_AGAIN }; -extern "C++" [[noreturn]] _CRTIMP2_PURE void __cdecl _Throw_C_error(int _Code); extern "C++" [[noreturn]] _CRTIMP2_PURE void __cdecl _Throw_Cpp_error(int _Code); _STD_END #pragma pop_macro("new") diff --git a/stl/src/thread0.cpp b/stl/src/thread0.cpp index bffe7faf63b..d3c8bbecf05 100644 --- a/stl/src/thread0.cpp +++ b/stl/src/thread0.cpp @@ -35,6 +35,7 @@ static constexpr errc codes[] = { _THROW(system_error(static_cast(codes[code]), _STD generic_category(), msgs[code])); } +// TRANSITION, ABI: preserved for binary compatibility [[noreturn]] _CRTIMP2_PURE void __cdecl _Throw_C_error(int code) { // throw error object for C error switch (code) { // select the exception case _Thrd_nomem: