Daniel Lehman : msvcp120: Implement _Thrd_current.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Nov 2 09:47:14 CST 2015


Module: wine
Branch: master
Commit: 498d8861e0378e3f3462256791b00598448b815e
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=498d8861e0378e3f3462256791b00598448b815e

Author: Daniel Lehman <dlehman at esri.com>
Date:   Wed Oct 28 11:26:18 2015 -0700

msvcp120: Implement _Thrd_current.

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

---

 dlls/msvcp110/msvcp110.spec         |  2 +-
 dlls/msvcp120/msvcp120.spec         |  2 +-
 dlls/msvcp120/tests/msvcp120.c      | 35 +++++++++++++++++++++++++++++++++++
 dlls/msvcp120_app/msvcp120_app.spec |  2 +-
 dlls/msvcp90/misc.c                 | 36 ++++++++++++++++++++++++++++++++++++
 5 files changed, 74 insertions(+), 3 deletions(-)

diff --git a/dlls/msvcp110/msvcp110.spec b/dlls/msvcp110/msvcp110.spec
index d227510..96ad84c 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 f316114..32be6ea 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 6cf8053..db14043 100644
--- a/dlls/msvcp120/tests/msvcp120.c
+++ b/dlls/msvcp120/tests/msvcp120.c
@@ -142,6 +142,20 @@ 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);
+
+#ifdef __i386__
+static ULONGLONG (__cdecl *p_i386_Thrd_current)(void);
+_Thrd_t __cdecl i386_Thrd_current(void)
+{
+    union {
+        _Thrd_t thr;
+        ULONGLONG ull;
+    } r;
+    r.ull = p_i386_Thrd_current();
+    return r.thr;
+}
+#endif
 
 static HMODULE msvcp;
 #define SETNOFAIL(x,y) x = (void*)GetProcAddress(msvcp,y)
@@ -220,6 +234,8 @@ static BOOL init(void)
                 "?_Last_write_time at sys@tr2 at std@@YA_JPEBD at Z");
         SET(p_tr2_sys__Last_write_time_set,
                 "?_Last_write_time at sys@tr2 at std@@YAXPEBD_J at Z");
+        SET(p__Thrd_current,
+                "_Thrd_current");
     } else {
         SET(p_tr2_sys__File_size,
                 "?_File_size at sys@tr2 at std@@YA_KPBD at Z");
@@ -265,6 +281,14 @@ static BOOL init(void)
                 "?_Last_write_time at sys@tr2 at std@@YA_JPBD at Z");
         SET(p_tr2_sys__Last_write_time_set,
                 "?_Last_write_time at sys@tr2 at std@@YAXPBD_J at Z");
+#ifdef __i386__
+        SET(p_i386_Thrd_current,
+                "_Thrd_current");
+        p__Thrd_current = i386_Thrd_current;
+#else
+        SET(p__Thrd_current,
+                "_Thrd_current");
+#endif
     }
     SET(p__Thrd_equal,
             "_Thrd_equal");
@@ -1151,6 +1175,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 +1216,16 @@ static void test_thrd(void)
     p_xtime_get(&after, 1);
     diff = p__Xtime_diff_to_millis2(&after, &before);
     ok(diff > 2000 - TIMEDELTA, "got %d\n", 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 b5d423b..fc77cfe 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..4bcc716 100644
--- a/dlls/msvcp90/misc.c
+++ b/dlls/msvcp90/misc.c
@@ -714,4 +714,40 @@ void __cdecl _Thrd_yield(void)
     TRACE("()\n");
     Sleep(0);
 }
+
+static _Thrd_t thread_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;
+}
+
+#ifndef __i386__
+_Thrd_t __cdecl _Thrd_current(void)
+{
+    return thread_current();
+}
+#else
+ULONGLONG __cdecl _Thrd_current(void)
+{
+    union {
+        _Thrd_t thr;
+        ULONGLONG ull;
+    } ret;
+
+    C_ASSERT(sizeof(_Thrd_t) <= sizeof(ULONGLONG));
+
+    ret.thr = thread_current();
+    return ret.ull;
+}
+#endif
 #endif




More information about the wine-cvs mailing list