From: Dan Kegel Subject: [PATCH 4/6] vcomp: better stub for omp_in_parallel Message-Id: <1349240286-15004-4-git-send-email-dank@kegel.com> Date: Tue, 2 Oct 2012 21:58:04 -0700 --- dlls/vcomp/fork.c | 13 ++++++++++++ dlls/vcomp/main.c | 15 ++++++++++++++ dlls/vcomp/tests/fork.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ dlls/vcomp/vcomp.spec | 2 +- dlls/vcomp/vcomp_private.h | 34 +++++++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 dlls/vcomp/vcomp_private.h diff --git a/dlls/vcomp/fork.c b/dlls/vcomp/fork.c index 47a3f7f..ca80c98 100644 --- a/dlls/vcomp/fork.c +++ b/dlls/vcomp/fork.c @@ -25,6 +25,7 @@ #include "windef.h" #include "winbase.h" #include "wine/debug.h" +#include "vcomp_private.h" WINE_DEFAULT_DEBUG_CHANNEL(vcomp); @@ -73,8 +74,13 @@ __ASM_GLOBAL_FUNC(_vcomp_fork, void CDECL _vcomp_fork_body(DWORD parallel, int nargs, void *helper, DWORD *args) { + struct vcomp_team team; + TRACE("(%d, %d, %p, %p): stub\n", parallel, nargs, helper, args); + team.parent = (struct vcomp_team *) TlsGetValue(vcomp_context_tls_idx); + TlsSetValue(vcomp_context_tls_idx, &team); _vcomp_fork_call_helper(helper, nargs, args); + TlsSetValue(vcomp_context_tls_idx, team.parent); } @@ -155,3 +161,10 @@ __ASM_GLOBAL_FUNC(_vcomp_fork_call_helper, __ASM_CFI(".cfi_same_value %rbp\n\t") "ret\n") #endif + +int CDECL omp_in_parallel(void) +{ + int val = (vcomp_get_team() != NULL); + TRACE("returning %d\n", val); + return val; +} diff --git a/dlls/vcomp/main.c b/dlls/vcomp/main.c index 5faf0a1..9db3b9d 100644 --- a/dlls/vcomp/main.c +++ b/dlls/vcomp/main.c @@ -29,6 +29,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(vcomp); +DWORD vcomp_context_tls_idx; + int CDECL omp_get_dynamic(void) { TRACE("stub\n"); @@ -101,8 +103,21 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) return FALSE; /* prefer native version */ case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls(hinstDLL); + + vcomp_context_tls_idx = TlsAlloc(); + if (vcomp_context_tls_idx == TLS_OUT_OF_INDEXES) + { + DWORD err = GetLastError(); + ERR("Failed to allocate TLS index, err %#x.\n", err); + return FALSE; + } break; case DLL_PROCESS_DETACH: + if (!TlsFree(vcomp_context_tls_idx)) + { + DWORD err = GetLastError(); + ERR("Failed to free context TLS index, err %#x.\n", err); + } break; } diff --git a/dlls/vcomp/tests/fork.c b/dlls/vcomp/tests/fork.c index a82a77b..9c37271 100644 --- a/dlls/vcomp/tests/fork.c +++ b/dlls/vcomp/tests/fork.c @@ -20,6 +20,9 @@ #include "wine/test.h" +static int CDECL (*pomp_get_num_threads)(void); +static int CDECL (*pomp_in_parallel)(void); +static void CDECL (*pomp_set_num_threads)(int); static void WINAPIV (*p_vcomp_fork)(DWORD parallel, int nargs, void *helper, ...); #define GETFUNC(x) do { p##x = (void*)GetProcAddress(vcomp, #x); ok(p##x != NULL, "Export '%s' not found\n", #x); } while(0) @@ -32,6 +35,9 @@ static BOOL init(void) return FALSE; } + GETFUNC(omp_get_num_threads); + GETFUNC(omp_in_parallel); + GETFUNC(omp_set_num_threads); GETFUNC(_vcomp_fork); return TRUE; @@ -72,10 +78,52 @@ static void test_vcomp_fork(void) ok(ncalls >= 1, "expected >= 1 call, got %d\n", ncalls); } +#define NLOOPS_SHORT 5 +#define SLEEP_MS_SHORT 50 + +static void CDECL _test_omp_in_parallel_nested_worker(LONG volatile *psum) +{ + if (pomp_in_parallel()) + InterlockedIncrement(psum); +} + +static void CDECL _test_omp_in_parallel_worker(LONG volatile *psum) +{ + int i; + InterlockedIncrement(psum); + for (i=0; i