| 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 "bin/thread.h" | 8 #include "bin/thread.h" |
| 9 #include "bin/thread_android.h" |
| 9 | 10 |
| 10 #include <errno.h> // NOLINT | 11 #include <errno.h> // NOLINT |
| 11 #include <sys/time.h> // NOLINT | 12 #include <sys/time.h> // NOLINT |
| 12 | 13 |
| 13 #include "platform/assert.h" | 14 #include "platform/assert.h" |
| 14 #include "platform/utils.h" | 15 #include "platform/utils.h" |
| 15 | 16 |
| 16 namespace dart { | 17 namespace dart { |
| 17 namespace bin { | 18 namespace bin { |
| 18 | 19 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 30 if (result != 0) { \ | 31 if (result != 0) { \ |
| 31 const int kBufferSize = 1024; \ | 32 const int kBufferSize = 1024; \ |
| 32 char error_message[kBufferSize]; \ | 33 char error_message[kBufferSize]; \ |
| 33 Utils::StrError(result, error_message, kBufferSize); \ | 34 Utils::StrError(result, error_message, kBufferSize); \ |
| 34 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", \ | 35 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", \ |
| 35 __FILE__, __LINE__, result, error_message); \ | 36 __FILE__, __LINE__, result, error_message); \ |
| 36 return result; \ | 37 return result; \ |
| 37 } | 38 } |
| 38 #else | 39 #else |
| 39 #define RETURN_ON_PTHREAD_FAILURE(result) \ | 40 #define RETURN_ON_PTHREAD_FAILURE(result) \ |
| 40 if (result != 0) return result; | 41 if (result != 0) { \ |
| 42 return result; \ |
| 43 } |
| 41 #endif | 44 #endif |
| 42 | 45 |
| 43 | 46 |
| 44 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { | 47 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { |
| 45 struct timeval tv; | 48 struct timeval tv; |
| 46 int64_t secs = micros / kMicrosecondsPerSecond; | 49 int64_t secs = micros / kMicrosecondsPerSecond; |
| 47 int64_t remaining_micros = (micros - (secs * kMicrosecondsPerSecond)); | 50 int64_t remaining_micros = (micros - (secs * kMicrosecondsPerSecond)); |
| 48 int result = gettimeofday(&tv, NULL); | 51 int result = gettimeofday(&tv, NULL); |
| 49 ASSERT(result == 0); | 52 ASSERT(result == 0); |
| 50 ts->tv_sec = tv.tv_sec + secs; | 53 ts->tv_sec = tv.tv_sec + secs; |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 160 } |
| 158 | 161 |
| 159 | 162 |
| 160 intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { | 163 intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { |
| 161 ASSERT(sizeof(id) == sizeof(intptr_t)); | 164 ASSERT(sizeof(id) == sizeof(intptr_t)); |
| 162 return static_cast<intptr_t>(id); | 165 return static_cast<intptr_t>(id); |
| 163 } | 166 } |
| 164 | 167 |
| 165 | 168 |
| 166 bool Thread::Compare(ThreadId a, ThreadId b) { | 169 bool Thread::Compare(ThreadId a, ThreadId b) { |
| 167 return a == b; | 170 return (a == b); |
| 168 } | 171 } |
| 169 | 172 |
| 170 | 173 |
| 171 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { | 174 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { |
| 172 ASSERT(thread_id == GetCurrentThreadId()); | 175 ASSERT(thread_id == GetCurrentThreadId()); |
| 173 ASSERT(cpu_usage != NULL); | 176 ASSERT(cpu_usage != NULL); |
| 174 struct timespec ts; | 177 struct timespec ts; |
| 175 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); | 178 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); |
| 176 ASSERT(r == 0); | 179 ASSERT(r == 0); |
| 177 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / | 180 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 void Monitor::NotifyAll() { | 329 void Monitor::NotifyAll() { |
| 327 // TODO(iposva): Do we need to track lock owners? | 330 // TODO(iposva): Do we need to track lock owners? |
| 328 int result = pthread_cond_broadcast(data_.cond()); | 331 int result = pthread_cond_broadcast(data_.cond()); |
| 329 VALIDATE_PTHREAD_RESULT(result); | 332 VALIDATE_PTHREAD_RESULT(result); |
| 330 } | 333 } |
| 331 | 334 |
| 332 } // namespace bin | 335 } // namespace bin |
| 333 } // namespace dart | 336 } // namespace dart |
| 334 | 337 |
| 335 #endif // defined(TARGET_OS_ANDROID) | 338 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |