Debian Codegraph @

nsprpub/pr/src/md/windows/ntdllmn.c

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 /*
7 * The DLL entry point (DllMain) for NSPR.
8 *
9 * The only reason we use DLLMain() now is to find out whether
10 * the NSPR DLL is statically or dynamically loaded. When
11 * dynamically loaded, we cannot use static thread-local storage.
12 * However, static TLS is faster than the TlsXXX() functions.
13 * So we want to use static TLS whenever we can. A global
14 * variable _pr_use_static_tls is set in DllMain() during process
15 * attachment to indicate whether it is safe to use static TLS
16 * or not.
17 */
18
19 #include <windows.h>
20 #include <primpl.h>
21
22 extern BOOL _pr_use_static_tls; /* defined in ntthread.c */
23
24 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
25 PRThread* me;
26
27 switch (fdwReason) {
28 case DLL_PROCESS_ATTACH:
29 /*
30 * If lpvReserved is NULL, we are dynamically loaded
31 * and therefore can't use static thread-local storage.
32 */
33 if (lpvReserved == NULL) {
34 _pr_use_static_tls = FALSE;
35 } else {
36 _pr_use_static_tls = TRUE;
37 }
38 break;
39 case DLL_THREAD_ATTACH:
40 break;
41 case DLL_THREAD_DETACH:
42 if (_pr_initialized) {
43 me = _MD_GET_ATTACHED_THREAD();
44 if ((me != NULL) && (me->flags & _PR_ATTACHED)) {
45 _PRI_DetachThread();
46 }
47 }
48 break;
49 case DLL_PROCESS_DETACH:
50 break;
51 }
52 return TRUE;
53 }