Module: wine Branch: master Commit: 277da0ea5d3e92815a417de4a4efbe44e7c6ad56 URL: http://source.winehq.org/git/wine.git/?a=commit;h=277da0ea5d3e92815a417de4a4...
Author: Iván Matellanes matellanesivan@gmail.com Date: Thu Jul 16 13:12:30 2015 +0200
msvcirt: Implement ios static locking.
---
dlls/msvcirt/msvcirt.c | 16 ++++++++++++++-- dlls/msvcirt/msvcirt.spec | 2 +- dlls/msvcirt/tests/msvcirt.c | 19 +++++++++++++++++-- dlls/msvcrt20/msvcrt20.spec | 2 +- dlls/msvcrt40/msvcrt40.spec | 2 +- 5 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/dlls/msvcirt/msvcirt.c b/dlls/msvcirt/msvcirt.c index 9c6b991..e46f574 100644 --- a/dlls/msvcirt/msvcirt.c +++ b/dlls/msvcirt/msvcirt.c @@ -31,6 +31,16 @@ WINE_DEFAULT_DEBUG_CHANNEL(msvcirt);
#define RESERVE_SIZE 512
+/* ?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A */ +extern CRITICAL_SECTION ios_static_lock; +CRITICAL_SECTION_DEBUG ios_static_lock_debug = +{ + 0, 0, &ios_static_lock, + { &ios_static_lock_debug.ProcessLocksList, &ios_static_lock_debug.ProcessLocksList }, + 0, 0, { (DWORD_PTR)(__FILE__ ": ios_static_lock") } +}; +CRITICAL_SECTION ios_static_lock = { &ios_static_lock_debug, -1, 0, 0, 0, 0 }; + /* class streambuf */ typedef struct { const vtable_ptr *vtable; @@ -1001,7 +1011,8 @@ void __cdecl ios_lockbuf(ios *this) /* ?lockc@ios@@KAXXZ */ void __cdecl ios_lockc(void) { - FIXME("() stub\n"); + TRACE("()\n"); + EnterCriticalSection(&ios_static_lock); }
/* ?lockptr@ios@@IAEPAU_CRT_CRITICAL_SECTION@@XZ */ @@ -1138,7 +1149,8 @@ void __cdecl ios_unlockbuf(ios *this) /* ?unlockc@ios@@KAXXZ */ void __cdecl ios_unlockc(void) { - FIXME("() stub\n"); + TRACE("()\n"); + LeaveCriticalSection(&ios_static_lock); }
/* ?unsetf@ios@@QAEJJ@Z */ diff --git a/dlls/msvcirt/msvcirt.spec b/dlls/msvcirt/msvcirt.spec index dc66bfa..8d26652 100644 --- a/dlls/msvcirt/msvcirt.spec +++ b/dlls/msvcirt/msvcirt.spec @@ -777,7 +777,7 @@ @ stub -arch=win32 ?ws@@YAAAVistream@@AAV1@@Z # class istream & __cdecl ws(class istream &) @ stub -arch=win64 ?ws@@YAAEAVistream@@AEAV1@@Z # @ extern ?x_curindex@ios@@0HA # static int ios::x_curindex -# @ extern ?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A # static struct _CRT_CRITICAL_SECTION ios::x_lockc +@ extern ?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A ios_static_lock # @ extern ?x_maxbit@ios@@0JA # static long ios::x_maxbit # @ extern ?x_statebuf@ios@@0PAJA # static long * ios::x_statebuf @ cdecl ?xalloc@ios@@SAHXZ() ios_xalloc diff --git a/dlls/msvcirt/tests/msvcirt.c b/dlls/msvcirt/tests/msvcirt.c index 944c024..523fb45 100644 --- a/dlls/msvcirt/tests/msvcirt.c +++ b/dlls/msvcirt/tests/msvcirt.c @@ -134,6 +134,9 @@ static void (*__cdecl p_ios_lock)(ios*); static void (*__cdecl p_ios_unlock)(ios*); static void (*__cdecl p_ios_lockbuf)(ios*); static void (*__cdecl p_ios_unlockbuf)(ios*); +static CRITICAL_SECTION *p_ios_static_lock; +static void (*__cdecl p_ios_lockc)(void); +static void (*__cdecl p_ios_unlockc)(void);
/* Emulate a __thiscall */ #ifdef __i386__ @@ -281,6 +284,9 @@ static BOOL init(void) SET(p_ios_lockbuf, "?lockbuf@ios@@QAAXXZ"); SET(p_ios_unlockbuf, "?unlockbuf@ios@@QAAXXZ"); } + SET(p_ios_static_lock, "?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A"); + SET(p_ios_lockc, "?lockc@ios@@KAXXZ"); + SET(p_ios_unlockc, "?unlockc@ios@@KAXXZ");
init_thiscall_thunk(); return TRUE; @@ -827,7 +833,7 @@ struct ios_lock_arg { ios *ios_obj; HANDLE lock; - HANDLE release[2]; + HANDLE release[3]; };
static DWORD WINAPI lock_ios(void *arg) @@ -835,10 +841,13 @@ static DWORD WINAPI lock_ios(void *arg) struct ios_lock_arg *lock_arg = arg; p_ios_lock(lock_arg->ios_obj); p_ios_lockbuf(lock_arg->ios_obj); + p_ios_lockc(); SetEvent(lock_arg->lock); WaitForSingleObject(lock_arg->release[0], INFINITE); - p_ios_unlockbuf(lock_arg->ios_obj); + p_ios_unlockc(); WaitForSingleObject(lock_arg->release[1], INFINITE); + p_ios_unlockbuf(lock_arg->ios_obj); + WaitForSingleObject(lock_arg->release[2], INFINITE); p_ios_unlock(lock_arg->ios_obj); return 0; } @@ -962,6 +971,8 @@ static void test_ios(void) ok(lock_arg.release[0] != NULL, "CreateEventW failed\n"); lock_arg.release[1] = CreateEventW(NULL, FALSE, FALSE, NULL); ok(lock_arg.release[1] != NULL, "CreateEventW failed\n"); + lock_arg.release[2] = CreateEventW(NULL, FALSE, FALSE, NULL); + ok(lock_arg.release[2] != NULL, "CreateEventW failed\n"); thread = CreateThread(NULL, 0, lock_ios, (void*)&lock_arg, 0, NULL); ok(thread != NULL, "CreateThread failed\n"); WaitForSingleObject(lock_arg.lock, INFINITE); @@ -970,9 +981,12 @@ static void test_ios(void) ok(locked == 0, "the ios object was not locked before\n"); locked = TryEnterCriticalSection(&ios_obj.sb->lock); ok(locked == 0, "the streambuf was not locked before\n"); + locked = TryEnterCriticalSection(p_ios_static_lock); + ok(locked == 0, "the static critical section was not locked before\n");
SetEvent(lock_arg.release[0]); SetEvent(lock_arg.release[1]); + SetEvent(lock_arg.release[2]); WaitForSingleObject(thread, INFINITE);
ios_obj.delbuf = 1; @@ -981,6 +995,7 @@ static void test_ios(void) CloseHandle(lock_arg.lock); CloseHandle(lock_arg.release[0]); CloseHandle(lock_arg.release[1]); + CloseHandle(lock_arg.release[2]); CloseHandle(thread); }
diff --git a/dlls/msvcrt20/msvcrt20.spec b/dlls/msvcrt20/msvcrt20.spec index 13b965c..b76b1d0 100644 --- a/dlls/msvcrt20/msvcrt20.spec +++ b/dlls/msvcrt20/msvcrt20.spec @@ -765,7 +765,7 @@ @ stub -arch=win32 ?ws@@YAAAVistream@@AAV1@@Z @ stub -arch=win64 ?ws@@YAAEAVistream@@AEAV1@@Z # @ extern ?x_curindex@ios@@0HA -# @ extern ?x_lockc@ios@@0U_RTL_CRITICAL_SECTION@@A +@ extern ?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A msvcirt.?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A # @ extern ?x_maxbit@ios@@0JA # @ extern ?x_statebuf@ios@@0QAJA @ cdecl ?xalloc@ios@@SAHXZ() msvcirt.?xalloc@ios@@SAHXZ diff --git a/dlls/msvcrt40/msvcrt40.spec b/dlls/msvcrt40/msvcrt40.spec index 924cd02..cfe2fea 100644 --- a/dlls/msvcrt40/msvcrt40.spec +++ b/dlls/msvcrt40/msvcrt40.spec @@ -839,7 +839,7 @@ @ stub -arch=win32 ?ws@@YAAAVistream@@AAV1@@Z @ stub -arch=win64 ?ws@@YAAEAVistream@@AEAV1@@Z # @ extern ?x_curindex@ios@@0HA -# @ extern ?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A +@ extern ?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A msvcirt.?x_lockc@ios@@0U_CRT_CRITICAL_SECTION@@A # @ extern ?x_maxbit@ios@@0JA # @ extern ?x_statebuf@ios@@0PAJA @ cdecl ?xalloc@ios@@SAHXZ() msvcirt.?xalloc@ios@@SAHXZ