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 | 6 #include "platform/signal_blocker.h" // NOLINT |
7 | 7 |
8 #if defined(TARGET_OS_LINUX) | 8 #if defined(TARGET_OS_LINUX) |
9 | 9 |
10 #include "vm/os_thread.h" | 10 #include "vm/os_thread.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 ThreadId OSThread::ThreadIdFromIntPtr(intptr_t id) { | 214 ThreadId OSThread::ThreadIdFromIntPtr(intptr_t id) { |
215 return static_cast<ThreadId>(id); | 215 return static_cast<ThreadId>(id); |
216 } | 216 } |
217 | 217 |
218 | 218 |
219 bool OSThread::Compare(ThreadId a, ThreadId b) { | 219 bool OSThread::Compare(ThreadId a, ThreadId b) { |
220 return pthread_equal(a, b) != 0; | 220 return pthread_equal(a, b) != 0; |
221 } | 221 } |
222 | 222 |
223 | 223 |
224 void OSThread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { | |
225 ASSERT(thread_id == GetCurrentThreadId()); | |
226 ASSERT(cpu_usage != NULL); | |
227 struct timespec ts; | |
228 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); | |
229 ASSERT(r == 0); | |
230 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / | |
231 kNanosecondsPerMicrosecond; | |
232 } | |
233 | |
234 | |
235 Mutex::Mutex() { | 224 Mutex::Mutex() { |
236 pthread_mutexattr_t attr; | 225 pthread_mutexattr_t attr; |
237 int result = pthread_mutexattr_init(&attr); | 226 int result = pthread_mutexattr_init(&attr); |
238 VALIDATE_PTHREAD_RESULT(result); | 227 VALIDATE_PTHREAD_RESULT(result); |
239 | 228 |
240 #if defined(DEBUG) | 229 #if defined(DEBUG) |
241 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); | 230 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); |
242 VALIDATE_PTHREAD_RESULT(result); | 231 VALIDATE_PTHREAD_RESULT(result); |
243 #endif // defined(DEBUG) | 232 #endif // defined(DEBUG) |
244 | 233 |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 void Monitor::NotifyAll() { | 437 void Monitor::NotifyAll() { |
449 // When running with assertions enabled we track the owner. | 438 // When running with assertions enabled we track the owner. |
450 ASSERT(IsOwnedByCurrentThread()); | 439 ASSERT(IsOwnedByCurrentThread()); |
451 int result = pthread_cond_broadcast(data_.cond()); | 440 int result = pthread_cond_broadcast(data_.cond()); |
452 VALIDATE_PTHREAD_RESULT(result); | 441 VALIDATE_PTHREAD_RESULT(result); |
453 } | 442 } |
454 | 443 |
455 } // namespace dart | 444 } // namespace dart |
456 | 445 |
457 #endif // defined(TARGET_OS_LINUX) | 446 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |