Chromium Code Reviews| 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_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include "platform/thread.h" | 8 #include "platform/thread.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 __FILE__, __LINE__, result, error_message); \ | 33 __FILE__, __LINE__, result, error_message); \ |
| 34 return result; \ | 34 return result; \ |
| 35 } | 35 } |
| 36 #else | 36 #else |
| 37 #define RETURN_ON_PTHREAD_FAILURE(result) \ | 37 #define RETURN_ON_PTHREAD_FAILURE(result) \ |
| 38 if (result != 0) return result; | 38 if (result != 0) return result; |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 | 41 |
| 42 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { | 42 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { |
| 43 struct timeval tv; | |
| 43 int64_t secs = micros / kMicrosecondsPerSecond; | 44 int64_t secs = micros / kMicrosecondsPerSecond; |
| 44 int64_t nanos = | 45 int64_t remaining_micros = (micros - (secs * kMicrosecondsPerSecond)); |
| 45 (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond; | 46 int result = gettimeofday(&tv, NULL); |
| 46 int result = clock_gettime(CLOCK_MONOTONIC, ts); | |
| 47 ASSERT(result == 0); | 47 ASSERT(result == 0); |
| 48 ts->tv_sec += secs; | 48 ts->tv_sec = tv.tv_sec + secs; |
| 49 ts->tv_nsec += nanos; | 49 ts->tv_nsec = (tv.tv_usec + remaining_micros) * kNanosecondsPerMicrosecond; |
| 50 if (ts->tv_nsec >= kNanosecondsPerSecond) { | 50 if (ts->tv_nsec >= kNanosecondsPerSecond) { |
| 51 ts->tv_sec += 1; | 51 ts->tv_sec += 1; |
| 52 ts->tv_nsec -= kNanosecondsPerSecond; | 52 ts->tv_nsec -= kNanosecondsPerSecond; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 class ThreadStartData { | 57 class ThreadStartData { |
| 58 public: | 58 public: |
| 59 ThreadStartData(Thread::ThreadStartFunction function, | 59 ThreadStartData(Thread::ThreadStartFunction function, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 } | 138 } |
| 139 | 139 |
| 140 | 140 |
| 141 intptr_t Thread::GetMaxStackSize() { | 141 intptr_t Thread::GetMaxStackSize() { |
| 142 const int kStackSize = (128 * kWordSize * KB); | 142 const int kStackSize = (128 * kWordSize * KB); |
| 143 return kStackSize; | 143 return kStackSize; |
| 144 } | 144 } |
| 145 | 145 |
| 146 | 146 |
| 147 ThreadId Thread::GetCurrentThreadId() { | 147 ThreadId Thread::GetCurrentThreadId() { |
| 148 return pthread_self(); | 148 return gettid(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 | 151 |
| 152 intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { | 152 intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { |
| 153 ASSERT(sizeof(id) == sizeof(intptr_t)); | 153 ASSERT(sizeof(id) == sizeof(intptr_t)); |
| 154 return static_cast<intptr_t>(id); | 154 return static_cast<intptr_t>(id); |
| 155 } | 155 } |
| 156 | 156 |
| 157 | 157 |
| 158 bool Thread::Compare(ThreadId a, ThreadId b) { | 158 bool Thread::Compare(ThreadId a, ThreadId b) { |
| 159 return pthread_equal(a, b) != 0; | 159 return pthread_equal(a, b) != 0; |
|
Cutch
2014/04/23 23:07:14
This needs to be updated.
zra
2014/04/23 23:12:07
Done.
| |
| 160 } | 160 } |
| 161 | 161 |
| 162 | 162 |
| 163 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { | 163 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { |
| 164 ASSERT(thread_id == GetCurrentThreadId()); | 164 ASSERT(thread_id == GetCurrentThreadId()); |
| 165 ASSERT(cpu_usage != NULL); | 165 ASSERT(cpu_usage != NULL); |
| 166 struct timespec ts; | 166 struct timespec ts; |
| 167 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); | 167 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); |
| 168 ASSERT(r == 0); | 168 ASSERT(r == 0); |
| 169 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / | 169 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 | 312 |
| 313 void Monitor::NotifyAll() { | 313 void Monitor::NotifyAll() { |
| 314 // TODO(iposva): Do we need to track lock owners? | 314 // TODO(iposva): Do we need to track lock owners? |
| 315 int result = pthread_cond_broadcast(data_.cond()); | 315 int result = pthread_cond_broadcast(data_.cond()); |
| 316 VALIDATE_PTHREAD_RESULT(result); | 316 VALIDATE_PTHREAD_RESULT(result); |
| 317 } | 317 } |
| 318 | 318 |
| 319 } // namespace dart | 319 } // namespace dart |
| 320 | 320 |
| 321 #endif // defined(TARGET_OS_ANDROID) | 321 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |