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 |
17 class ThreadStartData { | 21 class ThreadStartData { |
18 public: | 22 public: |
19 ThreadStartData(OSThread::ThreadStartFunction function, uword parameter) | 23 ThreadStartData(OSThread::ThreadStartFunction function, uword parameter) |
20 : function_(function), parameter_(parameter) {} | 24 : function_(function), parameter_(parameter) {} |
21 | 25 |
22 OSThread::ThreadStartFunction function() const { return function_; } | 26 OSThread::ThreadStartFunction function() const { return function_; } |
23 uword parameter() const { return parameter_; } | 27 uword parameter() const { return parameter_; } |
24 | 28 |
25 private: | 29 private: |
26 OSThread::ThreadStartFunction function_; | 30 OSThread::ThreadStartFunction function_; |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 631 |
628 #else // _WIN64 | 632 #else // _WIN64 |
629 | 633 |
630 #pragma comment(linker, "/INCLUDE:__tls_used") | 634 #pragma comment(linker, "/INCLUDE:__tls_used") |
631 #pragma comment(linker, "/INCLUDE:_p_thread_callback_dart") | 635 #pragma comment(linker, "/INCLUDE:_p_thread_callback_dart") |
632 | 636 |
633 #endif // _WIN64 | 637 #endif // _WIN64 |
634 | 638 |
635 // Static callback function to call with each thread termination. | 639 // Static callback function to call with each thread termination. |
636 void NTAPI OnDartThreadExit(PVOID module, DWORD reason, PVOID reserved) { | 640 void NTAPI OnDartThreadExit(PVOID module, DWORD reason, PVOID reserved) { |
| 641 if (!dart::private_flag_windows_run_tls_destructors) { |
| 642 return; |
| 643 } |
637 // On XP SP0 & SP1, the DLL_PROCESS_ATTACH is never seen. It is sent on SP2+ | 644 // On XP SP0 & SP1, the DLL_PROCESS_ATTACH is never seen. It is sent on SP2+ |
638 // and on W2K and W2K3. So don't assume it is sent. | 645 // and on W2K and W2K3. So don't assume it is sent. |
639 if (DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) { | 646 if (DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) { |
640 dart::ThreadLocalData::RunDestructors(); | 647 dart::ThreadLocalData::RunDestructors(); |
641 dart::MonitorWaitData::ThreadExit(); | 648 dart::MonitorWaitData::ThreadExit(); |
642 } | 649 } |
643 } | 650 } |
644 | 651 |
645 // .CRT$XLA to .CRT$XLZ is an array of PIMAGE_TLS_CALLBACK pointers that are | 652 // .CRT$XLA to .CRT$XLZ is an array of PIMAGE_TLS_CALLBACK pointers that are |
646 // called automatically by the OS loader code (not the CRT) when the module is | 653 // called automatically by the OS loader code (not the CRT) when the module is |
(...skipping 30 matching lines...) Expand all Loading... |
677 #pragma data_seg(".CRT$XLB") | 684 #pragma data_seg(".CRT$XLB") |
678 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit; | 685 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit; |
679 | 686 |
680 // Reset the default section. | 687 // Reset the default section. |
681 #pragma data_seg() | 688 #pragma data_seg() |
682 | 689 |
683 #endif // _WIN64 | 690 #endif // _WIN64 |
684 } // extern "C" | 691 } // extern "C" |
685 | 692 |
686 #endif // defined(TARGET_OS_WINDOWS) | 693 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |