Commit a283d14b authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

vcomp: Implement omp_init_lock and omp_destroy_lock.

parent ce18a733
......@@ -34,6 +34,9 @@
WINE_DEFAULT_DEBUG_CHANNEL(vcomp);
typedef CRITICAL_SECTION *omp_lock_t;
typedef CRITICAL_SECTION *omp_nest_lock_t;
static struct list vcomp_idle_threads = LIST_INIT(vcomp_idle_threads);
static DWORD vcomp_context_tls = TLS_OUT_OF_INDEXES;
static HMODULE vcomp_module;
......@@ -1020,29 +1023,49 @@ void WINAPIV _vcomp_fork(BOOL ifval, int nargs, void *wrapper, ...)
__ms_va_end(team_data.valist);
}
static CRITICAL_SECTION *alloc_critsect(void)
{
CRITICAL_SECTION *critsect;
if (!(critsect = HeapAlloc(GetProcessHeap(), 0, sizeof(*critsect))))
{
ERR("could not allocate critical section\n");
ExitProcess(1);
}
InitializeCriticalSection(critsect);
critsect->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": critsect");
return critsect;
}
static void destroy_critsect(CRITICAL_SECTION *critsect)
{
if (!critsect) return;
critsect->DebugInfo->Spare[0] = 0;
DeleteCriticalSection(critsect);
HeapFree(GetProcessHeap(), 0, critsect);
}
void CDECL omp_init_lock(omp_lock_t *lock)
{
TRACE("(%p)\n", lock);
*lock = alloc_critsect();
}
void CDECL omp_destroy_lock(omp_lock_t *lock)
{
TRACE("(%p)\n", lock);
destroy_critsect(*lock);
}
void CDECL _vcomp_enter_critsect(CRITICAL_SECTION **critsect)
{
TRACE("(%p)\n", critsect);
if (!*critsect)
{
CRITICAL_SECTION *new_critsect;
if (!(new_critsect = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_critsect))))
{
ERR("could not allocate critical section\n");
ExitProcess(1);
}
InitializeCriticalSection(new_critsect);
new_critsect->DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": critsect");
CRITICAL_SECTION *new_critsect = alloc_critsect();
if (interlocked_cmpxchg_ptr((void **)critsect, new_critsect, NULL) != NULL)
{
/* someone beat us to it */
new_critsect->DebugInfo->Spare[0] = 0;
DeleteCriticalSection(new_critsect);
HeapFree(GetProcessHeap(), 0, new_critsect);
}
destroy_critsect(new_critsect); /* someone beat us to it */
}
EnterCriticalSection(*critsect);
......
......@@ -88,7 +88,7 @@
@ cdecl _vcomp_set_num_threads(long)
@ cdecl _vcomp_single_begin(long)
@ cdecl _vcomp_single_end()
@ stub omp_destroy_lock
@ cdecl omp_destroy_lock(ptr)
@ stub omp_destroy_nest_lock
@ cdecl omp_get_dynamic()
@ cdecl omp_get_max_threads()
......@@ -99,7 +99,7 @@
@ stub omp_get_wtick
@ cdecl omp_get_wtime()
@ cdecl omp_in_parallel()
@ stub omp_init_lock
@ cdecl omp_init_lock(ptr)
@ stub omp_init_nest_lock
@ cdecl omp_set_dynamic(long)
@ stub omp_set_lock
......
......@@ -88,7 +88,7 @@
@ cdecl _vcomp_set_num_threads(long) vcomp._vcomp_set_num_threads
@ cdecl _vcomp_single_begin(long) vcomp._vcomp_single_begin
@ cdecl _vcomp_single_end() vcomp._vcomp_single_end
@ stub omp_destroy_lock
@ cdecl omp_destroy_lock(ptr) vcomp.omp_destroy_lock
@ stub omp_destroy_nest_lock
@ cdecl omp_get_dynamic() vcomp.omp_get_dynamic
@ cdecl omp_get_max_threads() vcomp.omp_get_max_threads
......@@ -99,7 +99,7 @@
@ stub omp_get_wtick
@ cdecl omp_get_wtime() vcomp.omp_get_wtime
@ cdecl omp_in_parallel() vcomp.omp_in_parallel
@ stub omp_init_lock
@ cdecl omp_init_lock(ptr) vcomp.omp_init_lock
@ stub omp_init_nest_lock
@ cdecl omp_set_dynamic(long) vcomp.omp_set_dynamic
@ stub omp_set_lock
......
......@@ -89,7 +89,7 @@
@ cdecl _vcomp_set_num_threads(long) vcomp._vcomp_set_num_threads
@ cdecl _vcomp_single_begin(long) vcomp._vcomp_single_begin
@ cdecl _vcomp_single_end() vcomp._vcomp_single_end
@ stub omp_destroy_lock
@ cdecl omp_destroy_lock(ptr) vcomp.omp_destroy_lock
@ stub omp_destroy_nest_lock
@ cdecl omp_get_dynamic() vcomp.omp_get_dynamic
@ cdecl omp_get_max_threads() vcomp.omp_get_max_threads
......@@ -100,7 +100,7 @@
@ stub omp_get_wtick
@ cdecl omp_get_wtime() vcomp.omp_get_wtime
@ cdecl omp_in_parallel() vcomp.omp_in_parallel
@ stub omp_init_lock
@ cdecl omp_init_lock(ptr) vcomp.omp_init_lock
@ stub omp_init_nest_lock
@ cdecl omp_set_dynamic(long) vcomp.omp_set_dynamic
@ stub omp_set_lock
......
......@@ -88,7 +88,7 @@
@ cdecl _vcomp_set_num_threads(long) vcomp._vcomp_set_num_threads
@ cdecl _vcomp_single_begin(long) vcomp._vcomp_single_begin
@ cdecl _vcomp_single_end() vcomp._vcomp_single_end
@ stub omp_destroy_lock
@ cdecl omp_destroy_lock(ptr) vcomp.omp_destroy_lock
@ stub omp_destroy_nest_lock
@ cdecl omp_get_dynamic() vcomp.omp_get_dynamic
@ cdecl omp_get_max_threads() vcomp.omp_get_max_threads
......@@ -99,7 +99,7 @@
@ stub omp_get_wtick
@ cdecl omp_get_wtime() vcomp.omp_get_wtime
@ cdecl omp_in_parallel() vcomp.omp_in_parallel
@ stub omp_init_lock
@ cdecl omp_init_lock(ptr) vcomp.omp_init_lock
@ stub omp_init_nest_lock
@ cdecl omp_set_dynamic(long) vcomp.omp_set_dynamic
@ stub omp_set_lock
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment