summaryrefslogtreecommitdiff
path: root/dll.c
diff options
context:
space:
mode:
authorrpj <rpj>1998-12-22 15:59:24 +0000
committerrpj <rpj>1998-12-22 15:59:24 +0000
commit95aa0a376d93ee021a6c085c71418e9f16513e0a (patch)
treef05f436e30d759df3af5cfe9e2cde62e3efa6f1b /dll.c
parent4650bcf1f1efd88a0c8f502c28945bfabd7ef6db (diff)
Sun Dec 20 14:51:58 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* misc.c (pthreadCancelableWait): New function by John Bossom. Non-stand ard but provides a hook that can be used to implement cancellation points in applications that use this library. * pthread.h (pthread_cleanup_pop): C++ (non-WIN32) version uses try/catch to emulate John Bossom's WIN32 __try/__finally behaviour. In the WIN32 version __finally block, add a test for AbnormalTermination otherwise cleanup is only run if the cleanup_pop execute arg is non-zero. Cancella tion should cause the cleanup to run irrespective of the execute arg. * condvar.c (pthread_condattr_init): Replaced by John Bossom's version. (pthread_condattr_destroy): Replaced by John Bossom's version. (pthread_condattr_getpshared): Replaced by John Bossom's version. (pthread_condattr_setpshared): Replaced by John Bossom's version. (pthread_cond_init): Replaced by John Bossom's version. Fix comment (refered to mutex rather than condition variable). (pthread_cond_destroy): Replaced by John Bossom's version. (pthread_cond_wait): Replaced by John Bossom's version. (pthread_cond_timedwait): Replaced by John Bossom's version. (pthread_cond_signal): Replaced by John Bossom's version. (pthread_cond_broadcast): Replaced by John Bossom's version. Thu Dec 17 19:10:46 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au> * tsd.c (pthread_key_create): Replaced by John Bossom's version. (pthread_key_delete): Replaced by John Bossom's version. (pthread_setspecific): Replaced by John Bossom's version. (pthread_getspecific): Replaced by John Bossom's version. Mon Dec 7 09:44:40 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au> * cancel.c (pthread_setcancelstate): Replaced by John Bossom's version. (pthread_setcanceltype): Replaced by John Bossom's version. (pthread_testcancel): Replaced by John Bossom's version. (pthread_cancel): Replaced by John Bossom's version. * exit.c (pthread_exit): Replaced by John Bossom's version. * misc.c (pthread_self): Replaced by John Bossom's version. (pthread_equal): Replaced by John Bossom's version. * sync.c (pthread_detach): Replaced by John Bossom's version. (pthread_join): Replaced by John Bossom's version. * create.c (pthread_create): Replaced by John Bossom's version. * private.c (_pthread_processInitialize): New by John Bossom. (_pthread_processTerminate): Non-public function by John Bossom. (_pthread_threadStart): Non-public function by John Bossom. (_pthread_threadDestroy): Non-public function by John Bossom. (_pthread_cleanupStack): Non-public function by John Bossom. (_pthread_tkAssocCreate): Non-public function by John Bossom. (_pthread_tkAssocDestroy): Non-public function by John Bossom. (_pthread_callUserDestroyRoutines): Non-public function by John Bossom. * implement.h: Added John Bossom's non-API structures and declarations. * dll.c (PthreadsEntryPoint): Cast return value of GetProcAddress to resolve compile warning from MSVC. * dll.c (DLLmain): Replaced by John Bossom's version. * dll.c (PthreadsEntryPoint): Re-applied Anders Norlander's patch:- Initialize _pthread_try_enter_critical_section at startup and release kernel32 handle when DLL is being unloaded.
Diffstat (limited to 'dll.c')
-rw-r--r--dll.c113
1 files changed, 108 insertions, 5 deletions
diff --git a/dll.c b/dll.c
index bb3d7ef..940a0dd 100644
--- a/dll.c
+++ b/dll.c
@@ -5,6 +5,112 @@
* This translation unit implements DLL initialisation.
*/
+#include <windows.h>
+#include <malloc.h>
+#include "pthread.h"
+#include "implement.h"
+
+
+/* Function pointer to TryEnterCriticalSection if it exists; otherwise NULL */
+BOOL (WINAPI *_pthread_try_enter_critical_section)(LPCRITICAL_SECTION) = NULL;
+
+/* Handle to kernel32.dll */
+static HINSTANCE _pthread_h_kernel32;
+
+#ifdef _WIN32
+/*
+ * lpvReserved yields an unreferenced formal parameter;
+ * ignore it
+ */
+#pragma warning( disable : 4100 )
+#endif
+
+BOOL WINAPI
+DllMain (
+ HINSTANCE hinstDll,
+ DWORD fdwReason,
+ LPVOID lpvReserved
+)
+{
+ BOOL result = TRUE;
+
+ switch (fdwReason)
+ {
+
+ case DLL_PROCESS_ATTACH:
+ /*
+ * The DLL is being mapped into the process's address space
+ */
+ result = _pthread_processInitialize ();
+
+ /* Load KERNEL32 and try to get address of TryEnterCriticalSection */
+ _pthread_h_kernel32 = LoadLibrary(TEXT("KERNEL32.DLL"));
+ _pthread_try_enter_critical_section =
+ (void *) GetProcAddress(_pthread_h_kernel32,
+ "TryEnterCriticalSection");
+ break;
+
+ case DLL_THREAD_ATTACH:
+ /*
+ * A thread is being created
+ */
+ result = TRUE;
+ break;
+
+ case DLL_THREAD_DETACH:
+ case DLL_PROCESS_DETACH:
+ /*
+ * A thread is exiting cleanly
+ * NOTE: The "main" thread detaches using
+ * DLL_PROCESS_DETACH
+ */
+ {
+ pthread_t self;
+
+ if (_pthread_processInitialized)
+ {
+#if defined( KLUDGE )
+ _pthread_cleanupStack ();
+#endif /* KLUDGE */
+
+ self = (pthread_t) pthread_getspecific (_pthread_selfThreadKey);
+
+ /*
+ * Detached threads have their resources automatically
+ * cleaned up upon exit (others must be 'joined'
+ */
+ if (self != NULL &&
+ self->detachState == PTHREAD_CREATE_DETACHED)
+ {
+
+ pthread_setspecific (_pthread_selfThreadKey, NULL);
+
+ _pthread_threadDestroy (self);
+ }
+
+ if (fdwReason == DLL_PROCESS_DETACH)
+ {
+ /*
+ * The DLL is being unmapped into the process's address space
+ */
+ _pthread_processTerminate ();
+ }
+ }
+
+ (void) FreeLibrary(_pthread_h_kernel32);
+
+ result = TRUE;
+ }
+ break;
+ }
+ return (result);
+
+} /* DllMain */
+
+
+
+#if 0 /* Pre Bossom */
+
/* We use the DLL entry point function to set up per thread storage
specifically to hold the threads own thread ID.
@@ -14,11 +120,6 @@
*/
-#include <windows.h>
-#include <malloc.h>
-#include "pthread.h"
-#include "implement.h"
-
/* Global index for TLS data. */
DWORD _pthread_threadID_TlsIndex;
@@ -78,3 +179,5 @@ BOOL WINAPI PthreadsEntryPoint(HINSTANCE dllHandle,
return TRUE;
}
+
+#endif /* Pre Bossom */