From e648469b0955d8a6f333e888b2b092b467ba4567 Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Wed, 28 Oct 2015 11:17:23 -0700 Subject: [PATCH 1/3] msvcp120: implement _Thrd_sleep/yield Signed-off-by: Daniel Lehman --- dlls/msvcp110/msvcp110.spec | 4 ++-- dlls/msvcp120/msvcp120.spec | 4 ++-- dlls/msvcp120/tests/msvcp120.c | 18 ++++++++++++++++++ dlls/msvcp120_app/msvcp120_app.spec | 4 ++-- dlls/msvcp90/misc.c | 12 ++++++++++++ 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/dlls/msvcp110/msvcp110.spec b/dlls/msvcp110/msvcp110.spec index 02ccf44..d227510 100644 --- a/dlls/msvcp110/msvcp110.spec +++ b/dlls/msvcp110/msvcp110.spec @@ -3863,9 +3863,9 @@ @ stub _Thrd_exit @ stub _Thrd_join @ cdecl _Thrd_lt(ptr ptr) -@ stub _Thrd_sleep +@ cdecl _Thrd_sleep(ptr) @ stub _Thrd_start -@ stub _Thrd_yield +@ cdecl _Thrd_yield() @ cdecl _Tolower(long ptr) @ cdecl _Toupper(long ptr) @ cdecl _Towlower(long ptr) diff --git a/dlls/msvcp120/msvcp120.spec b/dlls/msvcp120/msvcp120.spec index 5b7ac61..f316114 100644 --- a/dlls/msvcp120/msvcp120.spec +++ b/dlls/msvcp120/msvcp120.spec @@ -3810,9 +3810,9 @@ @ stub _Thrd_exit @ stub _Thrd_join @ cdecl _Thrd_lt(ptr ptr) -@ stub _Thrd_sleep +@ cdecl _Thrd_sleep(ptr) @ stub _Thrd_start -@ stub _Thrd_yield +@ cdecl _Thrd_yield() @ cdecl _Tolower(long ptr) @ cdecl _Toupper(long ptr) @ cdecl _Towlower(long ptr) diff --git a/dlls/msvcp120/tests/msvcp120.c b/dlls/msvcp120/tests/msvcp120.c index 3f24d05..6cf8053 100644 --- a/dlls/msvcp120/tests/msvcp120.c +++ b/dlls/msvcp120/tests/msvcp120.c @@ -137,8 +137,11 @@ typedef struct DWORD id; } _Thrd_t; +#define TIMEDELTA 150 /* 150 ms uncertainty allowed */ + 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 HMODULE msvcp; #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y) @@ -267,6 +270,8 @@ static BOOL init(void) "_Thrd_equal"); SET(p__Thrd_lt, "_Thrd_lt"); + SET(p__Thrd_sleep, + "_Thrd_sleep"); msvcr = GetModuleHandleA("msvcr120.dll"); p_setlocale = (void*)GetProcAddress(msvcr, "setlocale"); @@ -1144,6 +1149,8 @@ static void test_thrd(void) }; const HANDLE hnd1 = (HANDLE)0xcccccccc; const HANDLE hnd2 = (HANDLE)0xdeadbeef; + xtime xt, before, after; + MSVCRT_long diff; struct test testeq[] = { { {0, 0}, {0, 0}, 1 }, @@ -1173,6 +1180,17 @@ static void test_thrd(void) ok(ret == testlt[i].r, "(%p %u) < (%p %u) expected %d, got %d\n", testlt[i].a.hnd, testlt[i].a.id, testlt[i].b.hnd, testlt[i].b.id, testlt[i].r, ret); } + + /* test for sleep */ + if (0) /* crash on Windows */ + p__Thrd_sleep(NULL); + p_xtime_get(&xt, 1); + xt.sec += 2; + p_xtime_get(&before, 1); + p__Thrd_sleep(&xt); + p_xtime_get(&after, 1); + diff = p__Xtime_diff_to_millis2(&after, &before); + ok(diff > 2000 - TIMEDELTA, "got %d\n", diff); } START_TEST(msvcp120) diff --git a/dlls/msvcp120_app/msvcp120_app.spec b/dlls/msvcp120_app/msvcp120_app.spec index 2701eee..b5d423b 100644 --- a/dlls/msvcp120_app/msvcp120_app.spec +++ b/dlls/msvcp120_app/msvcp120_app.spec @@ -3810,9 +3810,9 @@ @ stub _Thrd_exit @ stub _Thrd_join @ cdecl _Thrd_lt(ptr ptr) msvcp120._Thrd_lt -@ stub _Thrd_sleep +@ cdecl _Thrd_sleep(ptr) msvcp120._Thrd_sleep @ stub _Thrd_start -@ stub _Thrd_yield +@ cdecl _Thrd_yield() msvcp120._Thrd_yield @ cdecl _Tolower(long ptr) msvcp120._Tolower @ cdecl _Toupper(long ptr) msvcp120._Toupper @ cdecl _Towlower(long ptr) msvcp120._Towlower diff --git a/dlls/msvcp90/misc.c b/dlls/msvcp90/misc.c index 2ec34fe..ccf1d04 100644 --- a/dlls/msvcp90/misc.c +++ b/dlls/msvcp90/misc.c @@ -702,4 +702,16 @@ int __cdecl _Thrd_lt(_Thrd_t a, _Thrd_t b) TRACE("(%p %u %p %u)\n", a.hnd, a.id, b.hnd, b.id); return a.id < b.id; } + +void __cdecl _Thrd_sleep(const xtime *t) +{ + TRACE("(%p)\n", t); + Sleep(_Xtime_diff_to_millis(t)); +} + +void __cdecl _Thrd_yield(void) +{ + TRACE("()\n"); + Sleep(0); +} #endif -- 1.9.5