Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: runtime/vm/os_thread_win.cc

Issue 1416063005: Hack around TLS destructors firing after the process exits (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.
zra 2015/11/03 22:55:12 Please add a TODO for me to try removing when shut
Cutch 2015/11/03 23:02:24 Done.
18 bool private_flag_windows_run_tls_destructors = true;
19
17 class ThreadStartData { 20 class ThreadStartData {
18 public: 21 public:
19 ThreadStartData(OSThread::ThreadStartFunction function, uword parameter) 22 ThreadStartData(OSThread::ThreadStartFunction function, uword parameter)
20 : function_(function), parameter_(parameter) {} 23 : function_(function), parameter_(parameter) {}
21 24
22 OSThread::ThreadStartFunction function() const { return function_; } 25 OSThread::ThreadStartFunction function() const { return function_; }
23 uword parameter() const { return parameter_; } 26 uword parameter() const { return parameter_; }
24 27
25 private: 28 private:
26 OSThread::ThreadStartFunction function_; 29 OSThread::ThreadStartFunction function_;
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 630
628 #else // _WIN64 631 #else // _WIN64
629 632
630 #pragma comment(linker, "/INCLUDE:__tls_used") 633 #pragma comment(linker, "/INCLUDE:__tls_used")
631 #pragma comment(linker, "/INCLUDE:_p_thread_callback_dart") 634 #pragma comment(linker, "/INCLUDE:_p_thread_callback_dart")
632 635
633 #endif // _WIN64 636 #endif // _WIN64
634 637
635 // Static callback function to call with each thread termination. 638 // Static callback function to call with each thread termination.
636 void NTAPI OnDartThreadExit(PVOID module, DWORD reason, PVOID reserved) { 639 void NTAPI OnDartThreadExit(PVOID module, DWORD reason, PVOID reserved) {
640 if (!dart::private_flag_windows_run_tls_destructors) {
641 return;
642 }
637 // On XP SP0 & SP1, the DLL_PROCESS_ATTACH is never seen. It is sent on SP2+ 643 // 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. 644 // and on W2K and W2K3. So don't assume it is sent.
639 if (DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) { 645 if (DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) {
640 dart::ThreadLocalData::RunDestructors(); 646 dart::ThreadLocalData::RunDestructors();
641 dart::MonitorWaitData::ThreadExit(); 647 dart::MonitorWaitData::ThreadExit();
642 } 648 }
643 } 649 }
644 650
645 // .CRT$XLA to .CRT$XLZ is an array of PIMAGE_TLS_CALLBACK pointers that are 651 // .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 652 // called automatically by the OS loader code (not the CRT) when the module is
(...skipping 30 matching lines...) Expand all
677 #pragma data_seg(".CRT$XLB") 683 #pragma data_seg(".CRT$XLB")
678 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit; 684 PIMAGE_TLS_CALLBACK p_thread_callback_dart = OnDartThreadExit;
679 685
680 // Reset the default section. 686 // Reset the default section.
681 #pragma data_seg() 687 #pragma data_seg()
682 688
683 #endif // _WIN64 689 #endif // _WIN64
684 } // extern "C" 690 } // extern "C"
685 691
686 #endif // defined(TARGET_OS_WINDOWS) 692 #endif // defined(TARGET_OS_WINDOWS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698