From 23095b9debf9ae963e61731ad4b76183c21dfe12 Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Wed, 28 Oct 2015 11:17:23 -0700 Subject: [PATCH] msvcp120: Implement _Thrd_sleep/yield. Signed-off-by: Daniel Lehman Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- 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 02ccf4403a7..d2275109c0b 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 5b7ac610cbd..f3161144cac 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 3f24d051487..6cf8053a3db 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 2701eee1640..b5d423bd374 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 2ec34fe5e3e..ccf1d047260 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