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