diff options
author | Stef Walter <stefw@gnome.org> | 2013-02-06 22:16:42 +0100 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-02-20 10:17:54 +0100 |
commit | 95ec58961a480c15fe780bbce6d6cd974f478407 (patch) | |
tree | ed8044874aec4d1a5a73c5a2dc7da55147fc19c5 /common | |
parent | c6ebe7eb68e07e4f22c7b7ede14a1e4f04e893b7 (diff) |
Only do shared object and DLL initialization in libraries
Don't do library initialization on shared object load when not running
in a library. We'll want to plug into this and do different things
per library in the future.
Diffstat (limited to 'common')
-rw-r--r-- | common/library.c | 60 | ||||
-rw-r--r-- | common/library.h | 2 |
2 files changed, 13 insertions, 49 deletions
diff --git a/common/library.c b/common/library.c index de340bb..0bc7e0c 100644 --- a/common/library.c +++ b/common/library.c @@ -176,18 +176,12 @@ p11_library_init_impl (void) pthread_key_create (&thread_local, free); } -#ifdef __GNUC__ -__attribute__((constructor)) -#endif void p11_library_init (void) { p11_library_init_once (); } -#ifdef __GNUC__ -__attribute__((destructor)) -#endif void p11_library_uninit (void) { @@ -233,17 +227,21 @@ p11_library_init (void) p11_debug ("initializing library"); p11_mutex_init (&p11_library_mutex); thread_local = TlsAlloc (); + if (thread_local == TLS_OUT_OF_INDEXES) + p11_debug ("couldn't setup tls"); } -static void -free_tls_value (LPVOID data) +void +p11_library_thread_cleanup (void) { p11_local *local = data; - if (local == NULL) - return; - if (local->last_error) - LocalFree (local->last_error); - LocalFree (data); + if (thread_local != TLS_OUT_OF_INDEXES) { + p11_debug ("thread stopped, freeing tls"); + local = TlsGetValue (thread_local); + if (local->last_error) + LocalFree (local->last_error); + LocalFree (local); + } } void @@ -261,40 +259,4 @@ p11_library_uninit (void) _p11_mutex_uninit (&p11_library_mutex); } - -BOOL WINAPI -DllMain (HINSTANCE instance, - DWORD reason, - LPVOID reserved) -{ - LPVOID data; - - switch (reason) { - case DLL_PROCESS_ATTACH: - p11_library_init (); - if (thread_local == TLS_OUT_OF_INDEXES) { - p11_debug ("couldn't setup tls"); - return FALSE; - } - break; - - case DLL_THREAD_DETACH: - if (thread_local != TLS_OUT_OF_INDEXES) { - p11_debug ("thread stopped, freeing tls"); - data = TlsGetValue (thread_local); - free_tls_value (data); - } - break; - - case DLL_PROCESS_DETACH: - p11_library_uninit (); - break; - - default: - break; - } - - return TRUE; -} - #endif /* OS_WIN32 */ diff --git a/common/library.h b/common/library.h index 338dc0f..b310cb9 100644 --- a/common/library.h +++ b/common/library.h @@ -79,6 +79,8 @@ void p11_library_init_impl (void); void p11_library_init (void); +void p11_library_thread_cleanup (void); + void p11_library_uninit (void); #endif /* P11_LIBRARY_H_ */ |