Skip to content

Commit f2633d3

Browse files
Cleanups: Simplify thread and condition_variable, identify unused dllexports (#3532)
1 parent 1e066dc commit f2633d3

File tree

7 files changed

+12
-30
lines changed

7 files changed

+12
-30
lines changed

stl/inc/condition_variable

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,8 @@ public:
224224
// but unfortunately our ABI speaks struct xtime, which is relative to the system clock.
225225
_CSTD xtime _Tgt;
226226
(void) _To_xtime_10_day_clamped(_Tgt, _Rel_time);
227-
const int _Res = _Cnd_timedwait(_Mycnd(), _Myptr->_Mymtx(), &_Tgt);
227+
(void) _Cnd_timedwait(_Mycnd(), _Myptr->_Mymtx(), &_Tgt);
228228
_Guard_unlocks_before_locking_outer.unlock();
229-
230-
switch (_Res) {
231-
case _Thrd_timedout:
232-
case _Thrd_success:
233-
break;
234-
default:
235-
_Throw_C_error(_Res);
236-
}
237229
} // relock
238230

239231
return _Pred();
@@ -262,13 +254,10 @@ private:
262254
const int _Res = _Cnd_timedwait(_Mycnd(), _Ptr->_Mymtx(), _Abs_time);
263255
_Guard.unlock();
264256

265-
switch (_Res) {
266-
case _Thrd_success:
257+
if (_Res == _Thrd_success) {
267258
return cv_status::no_timeout;
268-
case _Thrd_timedout:
259+
} else {
269260
return cv_status::timeout;
270-
default:
271-
_Throw_C_error(_Res);
272261
}
273262
}
274263
};

stl/inc/mutex

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -746,13 +746,11 @@ public:
746746

747747
// Nothing to do to comply with LWG-2135 because std::mutex lock/unlock are nothrow
748748
const int _Res = _Cnd_timedwait(_Mycnd(), _Lck.mutex()->_Mymtx(), _Abs_time);
749-
switch (_Res) {
750-
case _Thrd_success:
749+
750+
if (_Res == _Thrd_success) {
751751
return cv_status::no_timeout;
752-
case _Thrd_timedout:
752+
} else {
753753
return cv_status::timeout;
754-
default:
755-
_Throw_C_error(_Res);
756754
}
757755
}
758756

stl/inc/thread

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ public:
137137
_Throw_Cpp_error(_INVALID_ARGUMENT);
138138
}
139139

140-
_Check_C_return(_Thrd_detach(_Thr));
140+
if (_Thrd_detach(_Thr) != _Thrd_success) {
141+
_Throw_Cpp_error(_INVALID_ARGUMENT);
142+
}
143+
141144
_Thr = {};
142145
}
143146

stl/inc/xthreads.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,7 @@ enum { // constants for error codes
129129
_RESOURCE_UNAVAILABLE_TRY_AGAIN
130130
};
131131

132-
extern "C++" [[noreturn]] _CRTIMP2_PURE void __cdecl _Throw_C_error(int _Code);
133132
extern "C++" [[noreturn]] _CRTIMP2_PURE void __cdecl _Throw_Cpp_error(int _Code);
134-
135-
inline int _Check_C_return(int _Res) { // throw exception on failure
136-
if (_Res != _Thrd_success) {
137-
_Throw_C_error(_Res);
138-
}
139-
140-
return _Res;
141-
}
142133
_STD_END
143134
#pragma pop_macro("new")
144135
_STL_RESTORE_CLANG_WARNINGS

stl/inc/xtimec.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ struct xtime { // store time with nanosecond resolution
2727

2828
_CRTIMP2_PURE int __cdecl xtime_get(xtime*, int);
2929

30-
_CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis(const xtime*);
3130
_CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis2(const xtime*, const xtime*);
3231
_CRTIMP2_PURE long long __cdecl _Xtime_get_ticks();
3332

stl/src/thread0.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static constexpr errc codes[] = {
3535
_THROW(system_error(static_cast<int>(codes[code]), _STD generic_category(), msgs[code]));
3636
}
3737

38+
// TRANSITION, ABI: preserved for binary compatibility
3839
[[noreturn]] _CRTIMP2_PURE void __cdecl _Throw_C_error(int code) { // throw error object for C error
3940
switch (code) { // select the exception
4041
case _Thrd_nomem:

stl/src/xtime.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ _CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis2(const xtime* xt1, const xtime*
6464
return static_cast<long>(diff.sec * _Msec_per_sec + (diff.nsec + _Nsec_per_msec - 1) / _Nsec_per_msec);
6565
}
6666

67+
// TRANSITION, ABI: preserved for binary compatibility
6768
_CRTIMP2_PURE long __cdecl _Xtime_diff_to_millis(const xtime* xt) { // convert time to milliseconds
6869
xtime now;
6970
xtime_get(&now, TIME_UTC);

0 commit comments

Comments
 (0)