Commit f2f0dead authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32/tests: Fix the thread test to cope with the Win95 InterlockedIncrement behavior.

parent 22949d94
...@@ -105,23 +105,22 @@ CreateThread ...@@ -105,23 +105,22 @@ CreateThread
it. It basically makes multithreaded execution linear, which defeats it. It basically makes multithreaded execution linear, which defeats
the purpose of multiple threads, but makes testing easy. */ the purpose of multiple threads, but makes testing easy. */
static HANDLE start_event, stop_event; static HANDLE start_event, stop_event;
static LONG num_syncing_threads, num_synced; static LONG num_synced;
static void init_thread_sync_helpers(LONG num_threads) static void init_thread_sync_helpers(void)
{ {
start_event = CreateEvent(NULL, TRUE, FALSE, NULL); start_event = CreateEvent(NULL, TRUE, FALSE, NULL);
ok(start_event != NULL, "CreateEvent failed\n"); ok(start_event != NULL, "CreateEvent failed\n");
stop_event = CreateEvent(NULL, TRUE, FALSE, NULL); stop_event = CreateEvent(NULL, TRUE, FALSE, NULL);
ok(stop_event != NULL, "CreateEvent failed\n"); ok(stop_event != NULL, "CreateEvent failed\n");
num_syncing_threads = num_threads; num_synced = -1;
num_synced = 0;
} }
static BOOL sync_threads_and_run_one(DWORD sync_id, DWORD my_id) static BOOL sync_threads_and_run_one(DWORD sync_id, DWORD my_id)
{ {
LONG num = InterlockedIncrement(&num_synced); LONG num = InterlockedIncrement(&num_synced);
assert(0 < num && num <= num_syncing_threads); assert(-1 <= num && num <= 1);
if (num == num_syncing_threads) if (num == 1)
{ {
ResetEvent( stop_event ); ResetEvent( stop_event );
SetEvent( start_event ); SetEvent( start_event );
...@@ -129,7 +128,7 @@ static BOOL sync_threads_and_run_one(DWORD sync_id, DWORD my_id) ...@@ -129,7 +128,7 @@ static BOOL sync_threads_and_run_one(DWORD sync_id, DWORD my_id)
else else
{ {
DWORD ret = WaitForSingleObject(start_event, 10000); DWORD ret = WaitForSingleObject(start_event, 10000);
ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed\n"); ok(ret == WAIT_OBJECT_0, "WaitForSingleObject failed %x\n",ret);
} }
return sync_id == my_id; return sync_id == my_id;
} }
...@@ -137,8 +136,8 @@ static BOOL sync_threads_and_run_one(DWORD sync_id, DWORD my_id) ...@@ -137,8 +136,8 @@ static BOOL sync_threads_and_run_one(DWORD sync_id, DWORD my_id)
static void resync_after_run(void) static void resync_after_run(void)
{ {
LONG num = InterlockedDecrement(&num_synced); LONG num = InterlockedDecrement(&num_synced);
assert(0 <= num && num < num_syncing_threads); assert(-1 <= num && num <= 1);
if (num == 0) if (num == -1)
{ {
ResetEvent( start_event ); ResetEvent( start_event );
SetEvent( stop_event ); SetEvent( stop_event );
...@@ -1171,7 +1170,7 @@ static void test_TLS(void) ...@@ -1171,7 +1170,7 @@ static void test_TLS(void)
DWORD ret; DWORD ret;
BOOL suc; BOOL suc;
init_thread_sync_helpers(2); init_thread_sync_helpers();
/* Allocate a TLS slot in the main thread to test for inheritance. */ /* Allocate a TLS slot in the main thread to test for inheritance. */
TLS_main = TlsAlloc(); TLS_main = TlsAlloc();
......
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