Commit 146df7da authored by Sebastian Lackner's avatar Sebastian Lackner Committed by Alexandre Julliard

vcomp: Implement OpenMP regular locking functions.

Native OpenMP also immediately terminates the process (without exception) when calling omp_set_lock while holding the lock from the same thread.
parent f212a137
......@@ -1045,6 +1045,12 @@ static void destroy_critsect(CRITICAL_SECTION *critsect)
HeapFree(GetProcessHeap(), 0, critsect);
}
static BOOL critsect_is_locked(CRITICAL_SECTION *critsect)
{
return critsect->OwningThread == ULongToHandle(GetCurrentThreadId()) &&
critsect->RecursionCount;
}
void CDECL omp_init_lock(omp_lock_t *lock)
{
TRACE("(%p)\n", lock);
......@@ -1057,6 +1063,35 @@ void CDECL omp_destroy_lock(omp_lock_t *lock)
destroy_critsect(*lock);
}
void CDECL omp_set_lock(omp_lock_t *lock)
{
TRACE("(%p)\n", lock);
if (critsect_is_locked(*lock))
{
ERR("omp_set_lock called while holding lock %p\n", *lock);
ExitProcess(1);
}
EnterCriticalSection(*lock);
}
void CDECL omp_unset_lock(omp_lock_t *lock)
{
TRACE("(%p)\n", lock);
LeaveCriticalSection(*lock);
}
int CDECL omp_test_lock(omp_lock_t *lock)
{
TRACE("(%p)\n", lock);
if (critsect_is_locked(*lock))
return 0;
return TryEnterCriticalSection(*lock);
}
void CDECL omp_set_nest_lock(omp_nest_lock_t *lock)
{
TRACE("(%p)\n", lock);
......
......@@ -82,10 +82,13 @@ static int (CDECL *pomp_get_thread_num)(void);
static int (CDECL *pomp_in_parallel)(void);
static void (CDECL *pomp_init_lock)(omp_lock_t *lock);
static void (CDECL *pomp_init_nest_lock)(omp_nest_lock_t *lock);
static void (CDECL *pomp_set_lock)(omp_lock_t *lock);
static void (CDECL *pomp_set_nest_lock)(omp_nest_lock_t *lock);
static void (CDECL *pomp_set_nested)(int nested);
static void (CDECL *pomp_set_num_threads)(int num_threads);
static int (CDECL *pomp_test_lock)(omp_lock_t *lock);
static int (CDECL *pomp_test_nest_lock)(omp_nest_lock_t *lock);
static void (CDECL *pomp_unset_lock)(omp_lock_t *lock);
static void (CDECL *pomp_unset_nest_lock)(omp_nest_lock_t *lock);
#define VCOMP_DYNAMIC_FLAGS_STATIC 0x01
......@@ -268,10 +271,13 @@ static BOOL init_vcomp(void)
VCOMP_GET_PROC(omp_in_parallel);
VCOMP_GET_PROC(omp_init_lock);
VCOMP_GET_PROC(omp_init_nest_lock);
VCOMP_GET_PROC(omp_set_lock);
VCOMP_GET_PROC(omp_set_nest_lock);
VCOMP_GET_PROC(omp_set_nested);
VCOMP_GET_PROC(omp_set_num_threads);
VCOMP_GET_PROC(omp_test_lock);
VCOMP_GET_PROC(omp_test_nest_lock);
VCOMP_GET_PROC(omp_unset_lock);
VCOMP_GET_PROC(omp_unset_nest_lock);
return TRUE;
......@@ -1302,6 +1308,40 @@ static void test_vcomp_flush(void)
p_vcomp_flush();
}
static void test_omp_init_lock(void)
{
omp_lock_t lock;
int ret;
pomp_init_lock(&lock);
/* test omp_set_lock */
pomp_set_lock(&lock);
pomp_unset_lock(&lock);
/* test omp_test_lock */
ret = pomp_test_lock(&lock);
ok(ret == 1, "expected ret == 1, got %d\n", ret);
ret = pomp_test_lock(&lock);
ok(ret == 0, "expected ret == 0, got %d\n", ret);
pomp_unset_lock(&lock);
/* test with EnterCriticalSection */
EnterCriticalSection(lock);
ret = pomp_test_lock(&lock);
todo_wine
ok(ret == 1, "expected ret == 1, got %d\n", ret);
if (ret)
{
ret = pomp_test_lock(&lock);
ok(ret == 0, "expected ret == 0, got %d\n", ret);
pomp_unset_lock(&lock);
}
LeaveCriticalSection(lock);
pomp_destroy_lock(&lock);
}
static void test_omp_init_nest_lock(void)
{
omp_nest_lock_t lock;
......@@ -1462,6 +1502,7 @@ START_TEST(vcomp)
test_vcomp_single_begin();
test_vcomp_enter_critsect();
test_vcomp_flush();
test_omp_init_lock();
test_omp_init_nest_lock();
test_atomic_integer32();
test_atomic_float();
......
......@@ -102,11 +102,11 @@
@ cdecl omp_init_lock(ptr)
@ cdecl omp_init_nest_lock(ptr) omp_init_lock
@ cdecl omp_set_dynamic(long)
@ stub omp_set_lock
@ cdecl omp_set_lock(ptr)
@ cdecl omp_set_nest_lock(ptr)
@ cdecl omp_set_nested(long)
@ cdecl omp_set_num_threads(long)
@ stub omp_test_lock
@ cdecl omp_test_lock(ptr)
@ cdecl omp_test_nest_lock(ptr)
@ stub omp_unset_lock
@ cdecl omp_unset_lock(ptr)
@ cdecl omp_unset_nest_lock(ptr)
......@@ -102,11 +102,11 @@
@ cdecl omp_init_lock(ptr) vcomp.omp_init_lock
@ cdecl omp_init_nest_lock(ptr) vcomp.omp_init_nest_lock
@ cdecl omp_set_dynamic(long) vcomp.omp_set_dynamic
@ stub omp_set_lock
@ cdecl omp_set_lock(ptr) vcomp.omp_set_lock
@ cdecl omp_set_nest_lock(ptr) vcomp.omp_set_nest_lock
@ cdecl omp_set_nested(long) vcomp.omp_set_nested
@ cdecl omp_set_num_threads(long) vcomp.omp_set_num_threads
@ stub omp_test_lock
@ cdecl omp_test_lock(ptr) vcomp.omp_test_lock
@ cdecl omp_test_nest_lock(ptr) vcomp.omp_test_nest_lock
@ stub omp_unset_lock
@ cdecl omp_unset_lock(ptr) vcomp.omp_unset_lock
@ cdecl omp_unset_nest_lock(ptr) vcomp.omp_unset_nest_lock
......@@ -103,11 +103,11 @@
@ cdecl omp_init_lock(ptr) vcomp.omp_init_lock
@ cdecl omp_init_nest_lock(ptr) vcomp.omp_init_nest_lock
@ cdecl omp_set_dynamic(long) vcomp.omp_set_dynamic
@ stub omp_set_lock
@ cdecl omp_set_lock(ptr) vcomp.omp_set_lock
@ cdecl omp_set_nest_lock(ptr) vcomp.omp_set_nest_lock
@ cdecl omp_set_nested(long) vcomp.omp_set_nested
@ cdecl omp_set_num_threads(long) vcomp.omp_set_num_threads
@ stub omp_test_lock
@ cdecl omp_test_lock(ptr) vcomp.omp_test_lock
@ cdecl omp_test_nest_lock(ptr) vcomp.omp_test_nest_lock
@ stub omp_unset_lock
@ cdecl omp_unset_lock(ptr) vcomp.omp_unset_lock
@ cdecl omp_unset_nest_lock(ptr) vcomp.omp_unset_nest_lock
......@@ -102,11 +102,11 @@
@ cdecl omp_init_lock(ptr) vcomp.omp_init_lock
@ cdecl omp_init_nest_lock(ptr) vcomp.omp_init_nest_lock
@ cdecl omp_set_dynamic(long) vcomp.omp_set_dynamic
@ stub omp_set_lock
@ cdecl omp_set_lock(ptr) vcomp.omp_set_lock
@ cdecl omp_set_nest_lock(ptr) vcomp.omp_set_nest_lock
@ cdecl omp_set_nested(long) vcomp.omp_set_nested
@ cdecl omp_set_num_threads(long) vcomp.omp_set_num_threads
@ stub omp_test_lock
@ cdecl omp_test_lock(ptr) vcomp.omp_test_lock
@ cdecl omp_test_nest_lock(ptr) vcomp.omp_test_nest_lock
@ stub omp_unset_lock
@ cdecl omp_unset_lock(ptr) vcomp.omp_unset_lock
@ cdecl omp_unset_nest_lock(ptr) vcomp.omp_unset_nest_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