OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkTLS.h" | 8 #include "SkTLS.h" |
9 #include "SkMutex.h" | 9 #include "SkMutex.h" |
10 | 10 |
11 static bool gOnce = false; | 11 static bool gOnce = false; |
12 static DWORD gTlsIndex; | 12 static DWORD gTlsIndex; |
13 SK_DECLARE_STATIC_MUTEX(gMutex); | 13 SK_DECLARE_STATIC_MUTEX(gMutex); |
14 | 14 |
15 void* SkTLS::PlatformGetSpecific(bool forceCreateTheSlot) { | 15 void* SkTLS::PlatformGetSpecific(bool forceCreateTheSlot) { |
16 if (!forceCreateTheSlot && !gOnce) { | 16 if (!forceCreateTheSlot && !gOnce) { |
17 return NULL; | 17 return nullptr; |
18 } | 18 } |
19 | 19 |
20 if (!gOnce) { | 20 if (!gOnce) { |
21 SkAutoMutexAcquire tmp(gMutex); | 21 SkAutoMutexAcquire tmp(gMutex); |
22 if (!gOnce) { | 22 if (!gOnce) { |
23 gTlsIndex = TlsAlloc(); | 23 gTlsIndex = TlsAlloc(); |
24 gOnce = true; | 24 gOnce = true; |
25 } | 25 } |
26 } | 26 } |
27 return TlsGetValue(gTlsIndex); | 27 return TlsGetValue(gTlsIndex); |
(...skipping 14 matching lines...) Expand all Loading... |
42 #else | 42 #else |
43 | 43 |
44 #pragma comment(linker, "/INCLUDE:__tls_used") | 44 #pragma comment(linker, "/INCLUDE:__tls_used") |
45 #pragma comment(linker, "/INCLUDE:_skia_tls_callback") | 45 #pragma comment(linker, "/INCLUDE:_skia_tls_callback") |
46 | 46 |
47 #endif | 47 #endif |
48 | 48 |
49 void NTAPI onTLSCallback(PVOID unused, DWORD reason, PVOID unused2) { | 49 void NTAPI onTLSCallback(PVOID unused, DWORD reason, PVOID unused2) { |
50 if ((DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) && gOnce)
{ | 50 if ((DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) && gOnce)
{ |
51 void* ptr = TlsGetValue(gTlsIndex); | 51 void* ptr = TlsGetValue(gTlsIndex); |
52 if (ptr != NULL) { | 52 if (ptr != nullptr) { |
53 SkTLS::Destructor(ptr); | 53 SkTLS::Destructor(ptr); |
54 TlsSetValue(gTlsIndex, NULL); | 54 TlsSetValue(gTlsIndex, nullptr); |
55 } | 55 } |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 extern "C" { | 59 extern "C" { |
60 | 60 |
61 #ifdef _WIN64 | 61 #ifdef _WIN64 |
62 | 62 |
63 #pragma const_seg(".CRT$XLB") | 63 #pragma const_seg(".CRT$XLB") |
64 extern const PIMAGE_TLS_CALLBACK skia_tls_callback; | 64 extern const PIMAGE_TLS_CALLBACK skia_tls_callback; |
65 const PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback; | 65 const PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback; |
66 #pragma const_seg() | 66 #pragma const_seg() |
67 | 67 |
68 #else | 68 #else |
69 | 69 |
70 #pragma data_seg(".CRT$XLB") | 70 #pragma data_seg(".CRT$XLB") |
71 PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback; | 71 PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback; |
72 #pragma data_seg() | 72 #pragma data_seg() |
73 | 73 |
74 #endif | 74 #endif |
75 } | 75 } |
OLD | NEW |