From 5b139506fad10eaf3010575eb8e90c492fa5954a Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Wed, 28 Oct 2015 11:26:18 -0700 Subject: [PATCH 2/3] msvcp120: implement _Thrd_current Signed-off-by: Daniel Lehman --- dlls/msvcp110/msvcp110.spec | 2 +- dlls/msvcp120/msvcp120.spec | 2 +- dlls/msvcp120/tests/msvcp120.c | 14 ++++++++++++++ dlls/msvcp120_app/msvcp120_app.spec | 2 +- dlls/msvcp90/misc.c | 16 ++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/dlls/msvcp110/msvcp110.spec b/dlls/msvcp110/msvcp110.spec index 4759fc7..e3da7e9 100644 --- a/dlls/msvcp110/msvcp110.spec +++ b/dlls/msvcp110/msvcp110.spec @@ -3857,7 +3857,7 @@ @ stub _Strxfrm @ stub _Thrd_abort @ stub _Thrd_create -@ stub _Thrd_current +@ cdecl _Thrd_current() @ stub _Thrd_detach @ cdecl _Thrd_equal(ptr ptr) @ stub _Thrd_exit diff --git a/dlls/msvcp120/msvcp120.spec b/dlls/msvcp120/msvcp120.spec index 6044283..64db8b2 100644 --- a/dlls/msvcp120/msvcp120.spec +++ b/dlls/msvcp120/msvcp120.spec @@ -3804,7 +3804,7 @@ @ stub _Strxfrm @ stub _Thrd_abort @ stub _Thrd_create -@ stub _Thrd_current +@ cdecl _Thrd_current() @ stub _Thrd_detach @ cdecl _Thrd_equal(ptr ptr) @ stub _Thrd_exit diff --git a/dlls/msvcp120/tests/msvcp120.c b/dlls/msvcp120/tests/msvcp120.c index ba1089b..6dea8a3 100644 --- a/dlls/msvcp120/tests/msvcp120.c +++ b/dlls/msvcp120/tests/msvcp120.c @@ -142,6 +142,7 @@ typedef struct static int (__cdecl *p__Thrd_equal)(_Thrd_t, _Thrd_t); static int (__cdecl *p__Thrd_lt)(_Thrd_t, _Thrd_t); static void (__cdecl *p__Thrd_sleep)(const xtime*); +static _Thrd_t (__cdecl *p__Thrd_current)(void); static HMODULE msvcp; #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y) @@ -272,6 +273,8 @@ static BOOL init(void) "_Thrd_lt"); SET(p__Thrd_sleep, "_Thrd_sleep"); + SET(p__Thrd_current, + "_Thrd_current"); msvcr = GetModuleHandleA("msvcr120.dll"); p_setlocale = (void*)GetProcAddress(msvcr, "setlocale"); @@ -1151,6 +1154,7 @@ static void test_thrd(void) const HANDLE hnd2 = (HANDLE)0xdeadbeef; xtime xt, before, after; MSVCRT_long diff; + _Thrd_t ta, tb; struct test testeq[] = { { {0, 0}, {0, 0}, 1 }, @@ -1191,6 +1195,16 @@ static void test_thrd(void) p_xtime_get(&after, 1); diff = p__Xtime_diff_to_millis2(&after, &before); ok((diff > 2000 - TIMEDELTA) && (diff < 2000 + TIMEDELTA), "got %d", diff); + + /* test for current */ + ta = p__Thrd_current(); + tb = p__Thrd_current(); + ok(ta.id == tb.id, "got a %d b %d\n", ta.id, tb.id); + ok(ta.id == GetCurrentThreadId(), "expected %d, got %d\n", GetCurrentThreadId(), ta.id); + /* these can be different if new threads are created at same time */ + ok(ta.hnd == tb.hnd, "got a %p b %p\n", ta.hnd, tb.hnd); + ok(!CloseHandle(ta.hnd), "handle %p not closed\n", ta.hnd); + ok(!CloseHandle(tb.hnd), "handle %p not closed\n", tb.hnd); } START_TEST(msvcp120) diff --git a/dlls/msvcp120_app/msvcp120_app.spec b/dlls/msvcp120_app/msvcp120_app.spec index 50e0c70..4f1a469 100644 --- a/dlls/msvcp120_app/msvcp120_app.spec +++ b/dlls/msvcp120_app/msvcp120_app.spec @@ -3804,7 +3804,7 @@ @ stub _Strxfrm @ stub _Thrd_abort @ stub _Thrd_create -@ stub _Thrd_current +@ cdecl _Thrd_current() msvcp120._Thrd_current @ stub _Thrd_detach @ cdecl _Thrd_equal(ptr ptr) msvcp120._Thrd_equal @ stub _Thrd_exit diff --git a/dlls/msvcp90/misc.c b/dlls/msvcp90/misc.c index ccf1d04..5575b01 100644 --- a/dlls/msvcp90/misc.c +++ b/dlls/msvcp90/misc.c @@ -714,4 +714,20 @@ void __cdecl _Thrd_yield(void) TRACE("()\n"); Sleep(0); } + +_Thrd_t __cdecl _Thrd_current(void) +{ + _Thrd_t ret; + + if(DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), + GetCurrentProcess(), &ret.hnd, 0, FALSE, DUPLICATE_SAME_ACCESS)) { + CloseHandle(ret.hnd); + } else { + ret.hnd = 0; + } + ret.id = GetCurrentThreadId(); + + TRACE("(%p %u)\n", ret.hnd, ret.id); + return ret; +} #endif -- 1.9.5