Piotr Caban : msvcp110: Introduce wrapper around critical_section functions.

Alexandre Julliard julliard at winehq.org
Tue Mar 15 17:57:50 CDT 2022


Module: wine
Branch: master
Commit: bd0d5dea13d8478d5bb88185551aff744ed9621e
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=bd0d5dea13d8478d5bb88185551aff744ed9621e

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Tue Mar 15 14:36:30 2022 +0100

msvcp110: Introduce wrapper around critical_section functions.

Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcp90/misc.c       | 30 ++++++---------------------
 dlls/msvcp90/msvcp90.h    | 10 ++++-----
 dlls/msvcp90/msvcp_main.c | 53 ++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 59 insertions(+), 34 deletions(-)

diff --git a/dlls/msvcp90/misc.c b/dlls/msvcp90/misc.c
index c7a56ad9e97..0ed75e233d8 100644
--- a/dlls/msvcp90/misc.c
+++ b/dlls/msvcp90/misc.c
@@ -706,24 +706,6 @@ unsigned int __cdecl _Random_device(void)
 #endif
 
 #if _MSVCP_VER >= 110
-#ifdef __ASM_USE_THISCALL_WRAPPER
-
-extern void *call_thiscall_func;
-__ASM_GLOBAL_FUNC(call_thiscall_func,
-        "popl %eax\n\t"
-        "popl %edx\n\t"
-        "popl %ecx\n\t"
-        "pushl %eax\n\t"
-        "jmp *%edx\n\t")
-
-#define call_func1(func,this) ((void* (WINAPI*)(void*,void*))&call_thiscall_func)(func,this)
-
-#else /* __i386__ */
-
-#define call_func1(func,this) func(this)
-
-#endif /* __i386__ */
-
 #define MTX_PLAIN 0x1
 #define MTX_TRY 0x2
 #define MTX_TIMED 0x4
@@ -753,7 +735,7 @@ void __cdecl _Mtx_init_in_situ(_Mtx_t mtx, int flags)
         FIXME("unknown flags ignored: %x\n", flags);
 
     mtx->flags = flags;
-    call_func1(critical_section_ctor, &mtx->cs);
+    cs_init(&mtx->cs);
     mtx->thread_id = -1;
     mtx->count = 0;
 }
@@ -767,12 +749,12 @@ int __cdecl _Mtx_init(_Mtx_t *mtx, int flags)
 
 void __cdecl _Mtx_destroy_in_situ(_Mtx_t mtx)
 {
-    call_func1(critical_section_dtor, &mtx->cs);
+    cs_destroy(&mtx->cs);
 }
 
 void __cdecl _Mtx_destroy(_Mtx_arg_t mtx)
 {
-    call_func1(critical_section_dtor, &MTX_T_FROM_ARG(mtx)->cs);
+    cs_destroy(&MTX_T_FROM_ARG(mtx)->cs);
     operator_delete(MTX_T_FROM_ARG(mtx));
 }
 
@@ -784,7 +766,7 @@ int __cdecl _Mtx_current_owns(_Mtx_arg_t mtx)
 int __cdecl _Mtx_lock(_Mtx_arg_t mtx)
 {
     if(MTX_T_FROM_ARG(mtx)->thread_id != GetCurrentThreadId()) {
-        call_func1(critical_section_lock, &MTX_T_FROM_ARG(mtx)->cs);
+        cs_lock(&MTX_T_FROM_ARG(mtx)->cs);
         MTX_T_FROM_ARG(mtx)->thread_id = GetCurrentThreadId();
     }else if(!(MTX_T_FROM_ARG(mtx)->flags & MTX_RECURSIVE)
             && MTX_T_FROM_ARG(mtx)->flags != MTX_PLAIN) {
@@ -801,14 +783,14 @@ int __cdecl _Mtx_unlock(_Mtx_arg_t mtx)
         return 0;
 
     MTX_T_FROM_ARG(mtx)->thread_id = -1;
-    call_func1(critical_section_unlock, &MTX_T_FROM_ARG(mtx)->cs);
+    cs_unlock(&MTX_T_FROM_ARG(mtx)->cs);
     return 0;
 }
 
 int __cdecl _Mtx_trylock(_Mtx_arg_t mtx)
 {
     if(MTX_T_FROM_ARG(mtx)->thread_id != GetCurrentThreadId()) {
-        if(!call_func1(critical_section_trylock, &MTX_T_FROM_ARG(mtx)->cs))
+        if(!cs_trylock(&MTX_T_FROM_ARG(mtx)->cs))
             return MTX_LOCKED;
         MTX_T_FROM_ARG(mtx)->thread_id = GetCurrentThreadId();
     }else if(!(MTX_T_FROM_ARG(mtx)->flags & MTX_RECURSIVE)
diff --git a/dlls/msvcp90/msvcp90.h b/dlls/msvcp90/msvcp90.h
index 113350c9aaf..9cddab8fe02 100644
--- a/dlls/msvcp90/msvcp90.h
+++ b/dlls/msvcp90/msvcp90.h
@@ -58,11 +58,11 @@ typedef struct
     void *tail;
 } critical_section;
 
-extern critical_section* (__thiscall *critical_section_ctor)(critical_section*);
-extern void (__thiscall *critical_section_dtor)(critical_section*);
-extern void (__thiscall *critical_section_lock)(critical_section*);
-extern void (__thiscall *critical_section_unlock)(critical_section*);
-extern bool (__thiscall *critical_section_trylock)(critical_section*);
+extern void cs_init(critical_section*);
+extern void cs_destroy(critical_section*);
+extern void cs_lock(critical_section*);
+extern void cs_unlock(critical_section*);
+extern bool cs_trylock(critical_section*);
 #endif
 
 #if _MSVCP_VER >= 100
diff --git a/dlls/msvcp90/msvcp_main.c b/dlls/msvcp90/msvcp_main.c
index cf37631da0e..43ec67c4b9e 100644
--- a/dlls/msvcp90/msvcp_main.c
+++ b/dlls/msvcp90/msvcp_main.c
@@ -57,11 +57,54 @@ DEFINE_VTBL_WRAPPER(56);
 void* (__cdecl *MSVCRT_set_new_handler)(void*);
 
 #if _MSVCP_VER >= 110
-critical_section* (__thiscall *critical_section_ctor)(critical_section*);
-void (__thiscall *critical_section_dtor)(critical_section*);
-void (__thiscall *critical_section_lock)(critical_section*);
-void (__thiscall *critical_section_unlock)(critical_section*);
-bool (__thiscall *critical_section_trylock)(critical_section*);
+#ifdef __ASM_USE_THISCALL_WRAPPER
+
+extern void *call_thiscall_func;
+__ASM_GLOBAL_FUNC(call_thiscall_func,
+        "popl %eax\n\t"
+        "popl %edx\n\t"
+        "popl %ecx\n\t"
+        "pushl %eax\n\t"
+        "jmp *%edx\n\t")
+
+#define call_func1(func,this) ((void* (WINAPI*)(void*,void*))&call_thiscall_func)(func,this)
+
+#else /* __i386__ */
+
+#define call_func1(func,this) func(this)
+
+#endif /* __i386__ */
+
+static critical_section* (__thiscall *critical_section_ctor)(critical_section*);
+static void (__thiscall *critical_section_dtor)(critical_section*);
+static void (__thiscall *critical_section_lock)(critical_section*);
+static void (__thiscall *critical_section_unlock)(critical_section*);
+static bool (__thiscall *critical_section_trylock)(critical_section*);
+
+void cs_init(critical_section *cs)
+{
+    call_func1(critical_section_ctor, cs);
+}
+
+void cs_destroy(critical_section *cs)
+{
+    call_func1(critical_section_dtor, cs);
+}
+
+void cs_lock(critical_section *cs)
+{
+    call_func1(critical_section_lock, cs);
+}
+
+void cs_unlock(critical_section *cs)
+{
+    call_func1(critical_section_unlock, cs);
+}
+
+bool cs_trylock(critical_section *cs)
+{
+    return call_func1(critical_section_trylock, cs);
+}
 #endif
 
 #if _MSVCP_VER >= 100




More information about the wine-cvs mailing list