vcomp: Implement _vcomp_set_num_threads and omp_get_thread_num.
This commit is contained in:
parent
800ca050df
commit
f59551c222
|
@ -29,10 +29,54 @@
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(vcomp);
|
WINE_DEFAULT_DEBUG_CHANNEL(vcomp);
|
||||||
|
|
||||||
|
static DWORD vcomp_context_tls = TLS_OUT_OF_INDEXES;
|
||||||
static int vcomp_max_threads;
|
static int vcomp_max_threads;
|
||||||
static int vcomp_num_threads;
|
static int vcomp_num_threads;
|
||||||
static BOOL vcomp_nested_fork = FALSE;
|
static BOOL vcomp_nested_fork = FALSE;
|
||||||
|
|
||||||
|
struct vcomp_thread_data
|
||||||
|
{
|
||||||
|
int thread_num;
|
||||||
|
int fork_threads;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline struct vcomp_thread_data *vcomp_get_thread_data(void)
|
||||||
|
{
|
||||||
|
return (struct vcomp_thread_data *)TlsGetValue(vcomp_context_tls);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void vcomp_set_thread_data(struct vcomp_thread_data *thread_data)
|
||||||
|
{
|
||||||
|
TlsSetValue(vcomp_context_tls, thread_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct vcomp_thread_data *vcomp_init_thread_data(void)
|
||||||
|
{
|
||||||
|
struct vcomp_thread_data *thread_data = vcomp_get_thread_data();
|
||||||
|
if (thread_data) return thread_data;
|
||||||
|
|
||||||
|
if (!(thread_data = HeapAlloc(GetProcessHeap(), 0, sizeof(*thread_data))))
|
||||||
|
{
|
||||||
|
ERR("could not create thread data\n");
|
||||||
|
ExitProcess(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
thread_data->thread_num = 0;
|
||||||
|
thread_data->fork_threads = 0;
|
||||||
|
|
||||||
|
vcomp_set_thread_data(thread_data);
|
||||||
|
return thread_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vcomp_free_thread_data(void)
|
||||||
|
{
|
||||||
|
struct vcomp_thread_data *thread_data = vcomp_get_thread_data();
|
||||||
|
if (!thread_data) return;
|
||||||
|
|
||||||
|
HeapFree(GetProcessHeap(), 0, thread_data);
|
||||||
|
vcomp_set_thread_data(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
int CDECL omp_get_dynamic(void)
|
int CDECL omp_get_dynamic(void)
|
||||||
{
|
{
|
||||||
TRACE("stub\n");
|
TRACE("stub\n");
|
||||||
|
@ -65,8 +109,8 @@ int CDECL omp_get_num_threads(void)
|
||||||
|
|
||||||
int CDECL omp_get_thread_num(void)
|
int CDECL omp_get_thread_num(void)
|
||||||
{
|
{
|
||||||
TRACE("stub\n");
|
TRACE("()\n");
|
||||||
return 0;
|
return vcomp_init_thread_data()->thread_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Time in seconds since "some time in the past" */
|
/* Time in seconds since "some time in the past" */
|
||||||
|
@ -100,7 +144,9 @@ void CDECL _vcomp_barrier(void)
|
||||||
|
|
||||||
void CDECL _vcomp_set_num_threads(int num_threads)
|
void CDECL _vcomp_set_num_threads(int num_threads)
|
||||||
{
|
{
|
||||||
TRACE("(%d): stub\n", num_threads);
|
TRACE("(%d)\n", num_threads);
|
||||||
|
if (num_threads >= 1)
|
||||||
|
vcomp_init_thread_data()->fork_threads = num_threads;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CDECL _vcomp_single_begin(int flags)
|
int CDECL _vcomp_single_begin(int flags)
|
||||||
|
@ -126,13 +172,35 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
{
|
{
|
||||||
SYSTEM_INFO sysinfo;
|
SYSTEM_INFO sysinfo;
|
||||||
DisableThreadLibraryCalls(instance);
|
|
||||||
|
if ((vcomp_context_tls = TlsAlloc()) == TLS_OUT_OF_INDEXES)
|
||||||
|
{
|
||||||
|
ERR("Failed to allocate TLS index\n");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
GetSystemInfo(&sysinfo);
|
GetSystemInfo(&sysinfo);
|
||||||
vcomp_max_threads = sysinfo.dwNumberOfProcessors;
|
vcomp_max_threads = sysinfo.dwNumberOfProcessors;
|
||||||
vcomp_num_threads = sysinfo.dwNumberOfProcessors;
|
vcomp_num_threads = sysinfo.dwNumberOfProcessors;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case DLL_PROCESS_DETACH:
|
||||||
|
{
|
||||||
|
if (reserved) break;
|
||||||
|
if (vcomp_context_tls != TLS_OUT_OF_INDEXES)
|
||||||
|
{
|
||||||
|
vcomp_free_thread_data();
|
||||||
|
TlsFree(vcomp_context_tls);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case DLL_THREAD_DETACH:
|
||||||
|
{
|
||||||
|
vcomp_free_thread_data();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
Loading…
Reference in New Issue