From a5d7849619bbb30f21f13fa896d9de3fe5a862db Mon Sep 17 00:00:00 2001 From: achabense <60953653+achabense@users.noreply.github.com> Date: Mon, 14 Aug 2023 08:16:47 +0800 Subject: [PATCH] relocate _Mtx_clear_owner and _Mtx_reset_owner --- stl/inc/xthreads.h | 5 ----- stl/src/cond.cpp | 12 ++++++++++++ stl/src/mutex.cpp | 10 ---------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/stl/inc/xthreads.h b/stl/inc/xthreads.h index 26302f0aea..7f78cec33f 100644 --- a/stl/inc/xthreads.h +++ b/stl/inc/xthreads.h @@ -107,11 +107,6 @@ _CRTIMP2_PURE _Thrd_result __cdecl _Mtx_lock(_Mtx_t); _CRTIMP2_PURE _Thrd_result __cdecl _Mtx_trylock(_Mtx_t); _CRTIMP2_PURE _Thrd_result __cdecl _Mtx_unlock(_Mtx_t); // TRANSITION, ABI: Always succeeds -#ifdef _CRTBLD -_CRTIMP2_PURE void __cdecl _Mtx_clear_owner(_Mtx_t); -_CRTIMP2_PURE void __cdecl _Mtx_reset_owner(_Mtx_t); -#endif // _CRTBLD - // shared mutex // these declarations must be in sync with those in sharedmutex.cpp void __cdecl _Smtx_lock_exclusive(_Smtx_t*); diff --git a/stl/src/cond.cpp b/stl/src/cond.cpp index 01d964ef6f..fa094b0440 100644 --- a/stl/src/cond.cpp +++ b/stl/src/cond.cpp @@ -48,6 +48,18 @@ _CRTIMP2_PURE void __cdecl _Cnd_destroy(const _Cnd_t cond) { // clean up } } +// TRANSITION, ABI: should be static; dllexported for binary compatibility +_CRTIMP2_PURE void __cdecl _Mtx_clear_owner(_Mtx_t mtx) { // set owner to nobody + mtx->_Thread_id = -1; + --mtx->_Count; +} + +// TRANSITION, ABI: should be static; dllexported for binary compatibility +_CRTIMP2_PURE void __cdecl _Mtx_reset_owner(_Mtx_t mtx) { // set owner to current thread + mtx->_Thread_id = static_cast(GetCurrentThreadId()); + ++mtx->_Count; +} + _CRTIMP2_PURE _Thrd_result __cdecl _Cnd_wait(const _Cnd_t cond, const _Mtx_t mtx) { // wait until signaled const auto cs = &mtx->_Critical_section; _Mtx_clear_owner(mtx); diff --git a/stl/src/mutex.cpp b/stl/src/mutex.cpp index ba8c2de344..98cf98d1cd 100644 --- a/stl/src/mutex.cpp +++ b/stl/src/mutex.cpp @@ -189,16 +189,6 @@ _CRTIMP2_PURE void* __cdecl _Mtx_getconcrtcs(_Mtx_t mtx) { // get internal cs im return &mtx->_Critical_section; } -_CRTIMP2_PURE void __cdecl _Mtx_clear_owner(_Mtx_t mtx) { // set owner to nobody - mtx->_Thread_id = -1; - --mtx->_Count; -} - -_CRTIMP2_PURE void __cdecl _Mtx_reset_owner(_Mtx_t mtx) { // set owner to current thread - mtx->_Thread_id = static_cast(GetCurrentThreadId()); - ++mtx->_Count; -} - _END_EXTERN_C /*