OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" // NOLINT | 5 #include "platform/globals.h" // NOLINT |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "vm/growable_array.h" | 8 #include "vm/growable_array.h" |
9 #include "vm/os_thread.h" | 9 #include "vm/os_thread.h" |
10 | 10 |
11 #include <process.h> // NOLINT | 11 #include <process.h> // NOLINT |
12 | 12 |
13 #include "platform/assert.h" | 13 #include "platform/assert.h" |
14 | 14 |
15 namespace dart { | 15 namespace dart { |
16 | 16 |
17 // This flag is flipped by platform_win.cc when the process is exiting. | |
18 // TODO(zra): Remove once VM shuts down cleanly. | |
19 bool private_flag_windows_run_tls_destructors = true; | |
20 | |
21 class ThreadStartData { | 17 class ThreadStartData { |
22 public: | 18 public: |
23 ThreadStartData(OSThread::ThreadStartFunction function, uword parameter) | 19 ThreadStartData(OSThread::ThreadStartFunction function, uword parameter) |
24 : function_(function), parameter_(parameter) {} | 20 : function_(function), parameter_(parameter) {} |
25 | 21 |
26 OSThread::ThreadStartFunction function() const { return function_; } | 22 OSThread::ThreadStartFunction function() const { return function_; } |
27 uword parameter() const { return parameter_; } | 23 uword parameter() const { return parameter_; } |
28 | 24 |
29 private: | 25 private: |
30 OSThread::ThreadStartFunction function_; | 26 OSThread::ThreadStartFunction function_; |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 | 627 |
632 #else // _WIN64 | 628 #else // _WIN64 |
633 | 629 |
634 #pragma comment(linker, "/INCLUDE:__tls_used") | 630 #pragma comment(linker, "/INCLUDE:__tls_used") |
635 #pragma comment(linker, "/INCLUDE:_p_thread_callback_dart") | 631 #pragma comment(linker, "/INCLUDE:_p_thread_callback_dart") |
636 | 632 |
637 #endif // _WIN64 | 633 #endif // _WIN64 |
638 | 634 |
639 // Static callback function to call with each thread termination. | 635 // Static callback function to call with each thread termination. |
640 void NTAPI OnDartThreadExit(PVOID module, DWORD reason, PVOID reserved) { | 636 void NTAPI OnDartThreadExit(PVOID module, DWORD reason, PVOID reserved) { |
641 if (!dart::private_flag_windows_run_tls_destructors) { | |
642 return; | |
643 } | |
644 // On XP SP0 & SP1, the DLL_PROCESS_ATTACH is never seen. It is sent on SP2+ | 637 // On XP SP0 & SP1, the DLL_PROCESS_ATTACH is never seen. It is sent on SP2+ |
645 // and on W2K and W2K3. So don't assume it is sent. | 638 // and on W2K and W2K3. So don't assume it is sent. |
646 if (DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) { | 639 if (DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) { |
647 dart::ThreadLocalData::RunDestructors(); | 640 dart::ThreadLocalData::RunDestructors(); |
648 dart::MonitorWaitData::ThreadExit(); | 641 dart::MonitorWaitData::ThreadExit(); |
649 } | 642 } |
650 } | 643 } |
651 | 644 |
652 // .CRT$XLA to .CRT$XLZ is an array of PIMAGE_TLS_CALLBACK pointers that are | 645 // .CRT$XLA to .CRT$XLZ is an array of PIMAGE_TLS_CALLBACK pointers that are |
653 // called automatically by the OS loader code (not the CRT) when the module is | 646 // called automatically by the OS loader code (not the CRT) when the module is |
(...skipping 30 matching lines...) Expand all Loading... |
684 #pragma data_seg(".CRT$XLB") | 677 #pragma data_seg(".CRT$XLB") |
685 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit; | 678 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit; |
686 | 679 |
687 // Reset the default section. | 680 // Reset the default section. |
688 #pragma data_seg() | 681 #pragma data_seg() |
689 | 682 |
690 #endif // _WIN64 | 683 #endif // _WIN64 |
691 } // extern "C" | 684 } // extern "C" |
692 | 685 |
693 #endif // defined(TARGET_OS_WINDOWS) | 686 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |