From 5002bd21d12e99b69bce7d0ce22dfa7e4cccb804 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 30 Oct 2008 15:39:50 +0100 Subject: [PATCH] kernel32: Moved the pthread emulation support to ntdll. --- dlls/kernel32/Makefile.in | 1 - dlls/kernel32/kernel_private.h | 5 +---- dlls/kernel32/process.c | 2 -- dlls/ntdll/Makefile.in | 1 + dlls/ntdll/ntdll_misc.h | 4 +++- dlls/{kernel32 => ntdll}/pthread.c | 14 +++++++------- dlls/ntdll/thread.c | 1 + 7 files changed, 13 insertions(+), 15 deletions(-) rename dlls/{kernel32 => ntdll}/pthread.c (97%) diff --git a/dlls/kernel32/Makefile.in b/dlls/kernel32/Makefile.in index 0f00b925fa6..ffbfae3757d 100644 --- a/dlls/kernel32/Makefile.in +++ b/dlls/kernel32/Makefile.in @@ -51,7 +51,6 @@ C_SRCS = \ powermgnt.c \ process.c \ profile.c \ - pthread.c \ relay16.c \ resource.c \ resource16.c \ diff --git a/dlls/kernel32/kernel_private.h b/dlls/kernel32/kernel_private.h index 8d697077193..ccece659f98 100644 --- a/dlls/kernel32/kernel_private.h +++ b/dlls/kernel32/kernel_private.h @@ -30,8 +30,7 @@ struct kernel_thread_data WORD htask16; /* Win16 task handle */ DWORD sys_count[4]; /* syslevel mutex entry counters */ struct tagSYSLEVEL *sys_mutex[4]; /* syslevel mutex pointers */ - void *pthread_data; /* private data for pthread emulation */ - void *pad[43]; /* change this if you add fields! */ + void *pad[44]; /* change this if you add fields! */ }; static inline struct kernel_thread_data *kernel_get_thread_data(void) @@ -71,8 +70,6 @@ extern HANDLE dos_handles[DOS_TABLE_SIZE]; extern const WCHAR *DIR_Windows; extern const WCHAR *DIR_System; -extern void PTHREAD_Init(void); - extern VOID SYSLEVEL_CheckNotLevel( INT level ); extern void FILE_SetDosError(void); diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c index 72d829b5187..c8aba4792f3 100644 --- a/dlls/kernel32/process.c +++ b/dlls/kernel32/process.c @@ -970,8 +970,6 @@ void __wine_kernel_init(void) /* Initialize everything */ - PTHREAD_Init(); - setbuf(stdout,NULL); setbuf(stderr,NULL); kernel32_handle = GetModuleHandleW(kernel32W); diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index 345b88fcf3f..0c6a947aa5a 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -30,6 +30,7 @@ C_SRCS = \ om.c \ path.c \ process.c \ + pthread.c \ reg.c \ relay.c \ resource.c \ diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h index 3317a6ac791..a8fcf635ed5 100644 --- a/dlls/ntdll/ntdll_misc.h +++ b/dlls/ntdll/ntdll_misc.h @@ -59,6 +59,7 @@ extern size_t get_signal_stack_total_size(void); extern void version_init( const WCHAR *appname ); extern void debug_init(void); extern HANDLE thread_init(void); +extern void pthread_init(void); extern void actctx_init(void); extern void virtual_init(void); extern void virtual_init_threading(void); @@ -180,8 +181,9 @@ struct ntdll_thread_data int reply_fd; /* 1e4 fd for receiving server replies */ int wait_fd[2]; /* 1e8 fd for sleeping server requests */ void *vm86_ptr; /* 1f0 data for vm86 mode */ + void *pthread_data; /* 1f4 private data for pthread emulation */ - void *pad[2]; /* 1f4 change this if you add fields! */ + void *pad[1]; /* 1f8 change this if you add fields! */ }; static inline struct ntdll_thread_data *ntdll_get_thread_data(void) diff --git a/dlls/kernel32/pthread.c b/dlls/ntdll/pthread.c similarity index 97% rename from dlls/kernel32/pthread.c rename to dlls/ntdll/pthread.c index 0628890d60e..60b6033c3f3 100644 --- a/dlls/kernel32/pthread.c +++ b/dlls/ntdll/pthread.c @@ -46,7 +46,7 @@ #include "windef.h" #include "winbase.h" #include "winternl.h" -#include "kernel_private.h" +#include "ntdll_misc.h" #include "wine/pthread.h" #define P_OUTPUT(stuff) write(2,stuff,strlen(stuff)) @@ -183,7 +183,7 @@ static void mutex_real_init( pthread_mutex_t *mutex ) CRITICAL_SECTION *critsect = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(CRITICAL_SECTION)); RtlInitializeCriticalSection(critsect); - if (InterlockedCompareExchangePointer((void**)&(((wine_mutex)mutex)->critsect),critsect,NULL) != NULL) { + if (interlocked_cmpxchg_ptr((void**)&(((wine_mutex)mutex)->critsect),critsect,NULL) != NULL) { /* too late, some other thread already did it */ RtlDeleteCriticalSection(critsect); RtlFreeHeap(GetProcessHeap(), 0, critsect); @@ -242,7 +242,7 @@ static void rwlock_real_init(pthread_rwlock_t *rwlock) RTL_RWLOCK *lock = RtlAllocateHeap(GetProcessHeap(), 0, sizeof(RTL_RWLOCK)); RtlInitializeResource(lock); - if (InterlockedCompareExchangePointer((void**)&(((wine_rwlock)rwlock)->lock),lock,NULL) != NULL) { + if (interlocked_cmpxchg_ptr((void**)&(((wine_rwlock)rwlock)->lock),lock,NULL) != NULL) { /* too late, some other thread already did it */ RtlDeleteResource(lock); RtlFreeHeap(GetProcessHeap(), 0, lock); @@ -363,7 +363,7 @@ static void wine_cond_real_init(pthread_cond_t *cond) NtCreateEvent( &detail->waiters_done, EVENT_ALL_ACCESS, NULL, FALSE, FALSE ); RtlInitializeCriticalSection (&detail->waiters_count_lock); - if (InterlockedCompareExchangePointer((void**)&(((wine_cond)cond)->cond), detail, NULL) != NULL) + if (interlocked_cmpxchg_ptr((void**)&(((wine_cond)cond)->cond), detail, NULL) != NULL) { /* too late, some other thread already did it */ P_OUTPUT("FIXME:pthread_cond_init:expect troubles...\n"); @@ -549,12 +549,12 @@ static int wine_pthread_equal(pthread_t thread1, pthread_t thread2) static void *wine_get_thread_data(void) { - return kernel_get_thread_data()->pthread_data; + return ntdll_get_thread_data()->pthread_data; } static void wine_set_thread_data( void *data ) { - kernel_get_thread_data()->pthread_data = data; + ntdll_get_thread_data()->pthread_data = data; } static const struct wine_pthread_callbacks callbacks = @@ -590,7 +590,7 @@ static const struct wine_pthread_callbacks callbacks = static struct wine_pthread_functions pthread_functions; -void PTHREAD_Init(void) +void pthread_init(void) { wine_pthread_get_functions( &pthread_functions, sizeof(pthread_functions) ); pthread_functions.init_process( &callbacks, sizeof(callbacks) ); diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c index db126bbeec3..54d93d4752d 100644 --- a/dlls/ntdll/thread.c +++ b/dlls/ntdll/thread.c @@ -342,6 +342,7 @@ HANDLE thread_init(void) user_shared_data->TickCountLowDeprecated = user_shared_data->u.TickCount.LowPart; user_shared_data->TickCountMultiplier = 1 << 24; + pthread_init(); return exe_file; }