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" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include "platform/thread.h" | 8 #include "platform/thread.h" |
9 | 9 |
10 #include <sys/errno.h> // NOLINT | 10 #include <sys/errno.h> // NOLINT |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 | 139 |
140 ThreadId Thread::GetCurrentThreadId() { | 140 ThreadId Thread::GetCurrentThreadId() { |
141 return pthread_self(); | 141 return pthread_self(); |
142 } | 142 } |
143 | 143 |
144 | 144 |
145 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { | 145 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { |
146 ASSERT(thread_id == GetCurrentThreadId()); | 146 ASSERT(thread_id == GetCurrentThreadId()); |
147 ASSERT(cpu_usage != NULL); | 147 ASSERT(cpu_usage != NULL); |
148 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; | 148 // TODO(johnmccutchan): Enable this after fixing issue with macos directory |
149 thread_basic_info_data_t info_data; | 149 // watcher. |
150 thread_basic_info_t info = &info_data; | 150 const bool get_cpu_usage = false; |
151 mach_port_t thread_port = mach_thread_self(); | 151 if (get_cpu_usage) { |
152 kern_return_t r = thread_info(thread_port, THREAD_BASIC_INFO, | 152 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; |
153 (thread_info_t)info, &count); | 153 thread_basic_info_data_t info_data; |
154 mach_port_deallocate(mach_task_self(), thread_port); | 154 thread_basic_info_t info = &info_data; |
155 if (r == KERN_SUCCESS) { | 155 mach_port_t thread_port = mach_thread_self(); |
156 *cpu_usage = (info->user_time.seconds * kMicrosecondsPerSecond) + | 156 kern_return_t r = thread_info(thread_port, THREAD_BASIC_INFO, |
157 info->user_time.microseconds; | 157 (thread_info_t)info, &count); |
158 return; | 158 mach_port_deallocate(mach_task_self(), thread_port); |
| 159 if (r == KERN_SUCCESS) { |
| 160 *cpu_usage = (info->user_time.seconds * kMicrosecondsPerSecond) + |
| 161 info->user_time.microseconds; |
| 162 return; |
| 163 } |
159 } | 164 } |
160 *cpu_usage = 0; | 165 *cpu_usage = 0; |
161 } | 166 } |
162 | 167 |
163 | 168 |
164 Mutex::Mutex() { | 169 Mutex::Mutex() { |
165 pthread_mutexattr_t attr; | 170 pthread_mutexattr_t attr; |
166 int result = pthread_mutexattr_init(&attr); | 171 int result = pthread_mutexattr_init(&attr); |
167 VALIDATE_PTHREAD_RESULT(result); | 172 VALIDATE_PTHREAD_RESULT(result); |
168 | 173 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 306 |
302 void Monitor::NotifyAll() { | 307 void Monitor::NotifyAll() { |
303 // TODO(iposva): Do we need to track lock owners? | 308 // TODO(iposva): Do we need to track lock owners? |
304 int result = pthread_cond_broadcast(data_.cond()); | 309 int result = pthread_cond_broadcast(data_.cond()); |
305 VALIDATE_PTHREAD_RESULT(result); | 310 VALIDATE_PTHREAD_RESULT(result); |
306 } | 311 } |
307 | 312 |
308 } // namespace dart | 313 } // namespace dart |
309 | 314 |
310 #endif // defined(TARGET_OS_MACOS) | 315 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |