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