From 1eeb3f614ec2cc3e8752b8c14504e8254a8a2402 Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Thu, 26 May 2016 20:27:53 -0700 Subject: [PATCH 1/2] msvcp140: Take _Mtx_t and _Cnd_t directly vs2013 and earlier take pointer to _Mtx_t/_Cnd_t except for _Mtx_init/_Cnd_init Signed-off-by: Daniel Lehman --- dlls/msvcp90/misc.c | 98 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 41 deletions(-) diff --git a/dlls/msvcp90/misc.c b/dlls/msvcp90/misc.c index 81a5fbb..6463510 100644 --- a/dlls/msvcp90/misc.c +++ b/dlls/msvcp90/misc.c @@ -468,6 +468,16 @@ typedef struct DWORD count; } *_Mtx_t; +#if _MSVCP_VER >= 140 +typedef _Mtx_t _Mtx_arg_t; +#define D(m) (m) +#define R(m) (m) +#else +typedef _Mtx_t *_Mtx_arg_t; +#define D(m) (*(m)) +#define R(m) (&(m)) +#endif + int __cdecl _Mtx_init(_Mtx_t *mtx, int flags) { if(flags & ~MTX_MULTI_LOCK) @@ -481,57 +491,57 @@ int __cdecl _Mtx_init(_Mtx_t *mtx, int flags) return 0; } -void __cdecl _Mtx_destroy(_Mtx_t *mtx) +void __cdecl _Mtx_destroy(_Mtx_arg_t mtx) { - call_func1(critical_section_dtor, &(*mtx)->cs); - MSVCRT_operator_delete(*mtx); + call_func1(critical_section_dtor, &D(mtx)->cs); + MSVCRT_operator_delete(D(mtx)); } -int __cdecl _Mtx_current_owns(_Mtx_t *mtx) +int __cdecl _Mtx_current_owns(_Mtx_arg_t mtx) { - return (*mtx)->thread_id == GetCurrentThreadId(); + return D(mtx)->thread_id == GetCurrentThreadId(); } -int __cdecl _Mtx_lock(_Mtx_t *mtx) +int __cdecl _Mtx_lock(_Mtx_arg_t mtx) { - if((*mtx)->thread_id != GetCurrentThreadId()) { - call_func1(critical_section_lock, &(*mtx)->cs); - (*mtx)->thread_id = GetCurrentThreadId(); - }else if(!((*mtx)->flags & MTX_MULTI_LOCK)) { + if(D(mtx)->thread_id != GetCurrentThreadId()) { + call_func1(critical_section_lock, &D(mtx)->cs); + D(mtx)->thread_id = GetCurrentThreadId(); + }else if(!(D(mtx)->flags & MTX_MULTI_LOCK)) { return MTX_LOCKED; } - (*mtx)->count++; + D(mtx)->count++; return 0; } -int __cdecl _Mtx_unlock(_Mtx_t *mtx) +int __cdecl _Mtx_unlock(_Mtx_arg_t mtx) { - if(--(*mtx)->count) + if(--D(mtx)->count) return 0; - (*mtx)->thread_id = -1; - call_func1(critical_section_unlock, &(*mtx)->cs); + D(mtx)->thread_id = -1; + call_func1(critical_section_unlock, &D(mtx)->cs); return 0; } -int __cdecl _Mtx_trylock(_Mtx_t *mtx) +int __cdecl _Mtx_trylock(_Mtx_arg_t mtx) { - if((*mtx)->thread_id != GetCurrentThreadId()) { - if(!call_func1(critical_section_trylock, &(*mtx)->cs)) + if(D(mtx)->thread_id != GetCurrentThreadId()) { + if(!call_func1(critical_section_trylock, &D(mtx)->cs)) return MTX_LOCKED; - (*mtx)->thread_id = GetCurrentThreadId(); - }else if(!((*mtx)->flags & MTX_MULTI_LOCK)) { + D(mtx)->thread_id = GetCurrentThreadId(); + }else if(!(D(mtx)->flags & MTX_MULTI_LOCK)) { return MTX_LOCKED; } - (*mtx)->count++; + D(mtx)->count++; return 0; } -critical_section* __cdecl _Mtx_getconcrtcs(_Mtx_t *mtx) +critical_section* __cdecl _Mtx_getconcrtcs(_Mtx_arg_t mtx) { - return &(*mtx)->cs; + return &D(mtx)->cs; } static inline LONG interlocked_dec_if_nonzero( LONG *dest ) @@ -552,6 +562,12 @@ typedef struct CONDITION_VARIABLE cv; } *_Cnd_t; +#if _MSVCP_VER >= 140 +typedef _Cnd_t _Cnd_arg_t; +#else +typedef _Cnd_t *_Cnd_arg_t; +#endif + static HANDLE keyed_event; int __cdecl _Cnd_init(_Cnd_t *cnd) @@ -570,9 +586,9 @@ int __cdecl _Cnd_init(_Cnd_t *cnd) return 0; } -int __cdecl _Cnd_wait(_Cnd_t *cnd, _Mtx_t *mtx) +int __cdecl _Cnd_wait(_Cnd_arg_t cnd, _Mtx_arg_t mtx) { - CONDITION_VARIABLE *cv = &(*cnd)->cv; + CONDITION_VARIABLE *cv = &D(cnd)->cv; InterlockedExchangeAdd( (LONG *)&cv->Ptr, 1 ); _Mtx_unlock(mtx); @@ -583,9 +599,9 @@ int __cdecl _Cnd_wait(_Cnd_t *cnd, _Mtx_t *mtx) return 0; } -int __cdecl _Cnd_timedwait(_Cnd_t *cnd, _Mtx_t *mtx, const xtime *xt) +int __cdecl _Cnd_timedwait(_Cnd_arg_t cnd, _Mtx_arg_t mtx, const xtime *xt) { - CONDITION_VARIABLE *cv = &(*cnd)->cv; + CONDITION_VARIABLE *cv = &D(cnd)->cv; LARGE_INTEGER timeout; NTSTATUS status; @@ -604,28 +620,28 @@ int __cdecl _Cnd_timedwait(_Cnd_t *cnd, _Mtx_t *mtx, const xtime *xt) return status ? CND_TIMEDOUT : 0; } -int __cdecl _Cnd_broadcast(_Cnd_t *cnd) +int __cdecl _Cnd_broadcast(_Cnd_arg_t cnd) { - CONDITION_VARIABLE *cv = &(*cnd)->cv; + CONDITION_VARIABLE *cv = &D(cnd)->cv; LONG val = InterlockedExchange( (LONG *)&cv->Ptr, 0 ); while (val-- > 0) NtReleaseKeyedEvent( keyed_event, &cv->Ptr, FALSE, NULL ); return 0; } -int __cdecl _Cnd_signal(_Cnd_t *cnd) +int __cdecl _Cnd_signal(_Cnd_arg_t cnd) { - CONDITION_VARIABLE *cv = &(*cnd)->cv; + CONDITION_VARIABLE *cv = &D(cnd)->cv; if (interlocked_dec_if_nonzero( (LONG *)&cv->Ptr )) NtReleaseKeyedEvent( keyed_event, &cv->Ptr, FALSE, NULL ); return 0; } -void __cdecl _Cnd_destroy(_Cnd_t *cnd) +void __cdecl _Cnd_destroy(_Cnd_arg_t cnd) { if(cnd) { _Cnd_broadcast(cnd); - MSVCRT_operator_delete(*cnd); + MSVCRT_operator_delete(D(cnd)); } } #endif @@ -953,7 +969,7 @@ _Pad* __thiscall _Pad_ctor(_Pad *this) _Cnd_init(&this->cnd); _Mtx_init(&this->mtx, 0); this->launched = FALSE; - _Mtx_lock(&this->mtx); + _Mtx_lock(R(this->mtx)); return this; } @@ -988,9 +1004,9 @@ void __thiscall _Pad_dtor(_Pad *this) { TRACE("(%p)\n", this); - _Mtx_unlock(&this->mtx); - _Mtx_destroy(&this->mtx); - _Cnd_destroy(&this->cnd); + _Mtx_unlock(R(this->mtx)); + _Mtx_destroy(R(this->mtx)); + _Cnd_destroy(R(this->cnd)); } DEFINE_THISCALL_WRAPPER(_Pad__Go, 4) @@ -1015,7 +1031,7 @@ void __thiscall _Pad__Launch(_Pad *this, _Thrd_t *thr) TRACE("(%p %p)\n", this, thr); _Thrd_start(thr, launch_thread_proc, this); - _Cnd_wait(&this->cnd, &this->mtx); + _Cnd_wait(R(this->cnd), R(this->mtx)); } /* ?_Release@_Pad@std@@QAEXXZ */ @@ -1025,10 +1041,10 @@ void __thiscall _Pad__Release(_Pad *this) { TRACE("(%p)\n", this); - _Mtx_lock(&this->mtx); + _Mtx_lock(R(this->mtx)); this->launched = TRUE; - _Cnd_signal(&this->cnd); - _Mtx_unlock(&this->mtx); + _Cnd_signal(R(this->cnd)); + _Mtx_unlock(R(this->mtx)); } #endif -- 1.9.5