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 #include "platform/signal_blocker.h" // NOLINT |
| 7 |
6 #if defined(TARGET_OS_LINUX) | 8 #if defined(TARGET_OS_LINUX) |
7 | 9 |
8 #include "vm/os_thread.h" | 10 #include "vm/os_thread.h" |
9 | 11 |
10 #include <errno.h> // NOLINT | 12 #include <errno.h> // NOLINT |
11 #include <sys/resource.h> // NOLINT | 13 #include <sys/resource.h> // NOLINT |
12 #include <sys/syscall.h> // NOLINT | 14 #include <sys/syscall.h> // NOLINT |
13 #include <sys/time.h> // NOLINT | 15 #include <sys/time.h> // NOLINT |
14 | 16 |
15 #include "platform/assert.h" | 17 #include "platform/assert.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 80 |
79 private: | 81 private: |
80 const char* name_; | 82 const char* name_; |
81 OSThread::ThreadStartFunction function_; | 83 OSThread::ThreadStartFunction function_; |
82 uword parameter_; | 84 uword parameter_; |
83 | 85 |
84 DISALLOW_COPY_AND_ASSIGN(ThreadStartData); | 86 DISALLOW_COPY_AND_ASSIGN(ThreadStartData); |
85 }; | 87 }; |
86 | 88 |
87 | 89 |
| 90 // Spawned threads inherit their spawner's signal mask. We sometimes spawn |
| 91 // threads for running Dart code from a thread that is blocking SIGPROF. |
| 92 // This function explicitly unblocks SIGPROF so the profiler continues to |
| 93 // sample this thread. |
| 94 static void UnblockSIGPROF() { |
| 95 sigset_t set; |
| 96 sigemptyset(&set); |
| 97 sigaddset(&set, SIGPROF); |
| 98 int r = pthread_sigmask(SIG_UNBLOCK, &set, NULL); |
| 99 USE(r); |
| 100 ASSERT(r == 0); |
| 101 ASSERT(!CHECK_IS_BLOCKING(SIGPROF)); |
| 102 } |
| 103 |
| 104 |
88 // Dispatch to the thread start function provided by the caller. This trampoline | 105 // Dispatch to the thread start function provided by the caller. This trampoline |
89 // is used to ensure that the thread is properly destroyed if the thread just | 106 // is used to ensure that the thread is properly destroyed if the thread just |
90 // exits. | 107 // exits. |
91 static void* ThreadStart(void* data_ptr) { | 108 static void* ThreadStart(void* data_ptr) { |
92 ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr); | 109 ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr); |
93 | 110 |
94 const char* name = data->name(); | 111 const char* name = data->name(); |
95 OSThread::ThreadStartFunction function = data->function(); | 112 OSThread::ThreadStartFunction function = data->function(); |
96 uword parameter = data->parameter(); | 113 uword parameter = data->parameter(); |
97 delete data; | 114 delete data; |
98 | 115 |
99 // Create new OSThread object and set as TLS for new thread. | 116 // Create new OSThread object and set as TLS for new thread. |
100 OSThread* thread = OSThread::CreateOSThread(); | 117 OSThread* thread = OSThread::CreateOSThread(); |
101 if (thread != NULL) { | 118 if (thread != NULL) { |
102 OSThread::SetCurrent(thread); | 119 OSThread::SetCurrent(thread); |
103 thread->set_name(name); | 120 thread->set_name(name); |
104 | 121 UnblockSIGPROF(); |
105 // Call the supplied thread start function handing it its parameters. | 122 // Call the supplied thread start function handing it its parameters. |
106 function(parameter); | 123 function(parameter); |
107 } | 124 } |
108 | 125 |
109 return NULL; | 126 return NULL; |
110 } | 127 } |
111 | 128 |
112 | 129 |
113 int OSThread::Start(const char* name, | 130 int OSThread::Start(const char* name, |
114 ThreadStartFunction function, | 131 ThreadStartFunction function, |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 void Monitor::NotifyAll() { | 448 void Monitor::NotifyAll() { |
432 // When running with assertions enabled we track the owner. | 449 // When running with assertions enabled we track the owner. |
433 ASSERT(IsOwnedByCurrentThread()); | 450 ASSERT(IsOwnedByCurrentThread()); |
434 int result = pthread_cond_broadcast(data_.cond()); | 451 int result = pthread_cond_broadcast(data_.cond()); |
435 VALIDATE_PTHREAD_RESULT(result); | 452 VALIDATE_PTHREAD_RESULT(result); |
436 } | 453 } |
437 | 454 |
438 } // namespace dart | 455 } // namespace dart |
439 | 456 |
440 #endif // defined(TARGET_OS_LINUX) | 457 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |