| 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 | 6 |
| 7 #if defined(TARGET_OS_LINUX) | 7 #if defined(TARGET_OS_LINUX) |
| 8 | 8 |
| 9 #include "vm/os_thread.h" | 9 #include "vm/os_thread.h" |
| 10 | 10 |
| 11 #include <errno.h> // NOLINT | 11 #include <errno.h> // NOLINT |
| 12 #include <sys/resource.h> // NOLINT | 12 #include <sys/resource.h> // NOLINT |
| 13 #include <sys/syscall.h> // NOLINT | 13 #include <sys/syscall.h> // NOLINT |
| 14 #include <sys/time.h> // NOLINT | 14 #include <sys/time.h> // NOLINT |
| 15 | 15 |
| 16 #include "platform/assert.h" | 16 #include "platform/assert.h" |
| 17 #include "platform/signal_blocker.h" | 17 #include "platform/signal_blocker.h" |
| 18 #include "platform/utils.h" | 18 #include "platform/utils.h" |
| 19 | 19 |
| 20 #include "vm/profiler.h" | 20 #include "vm/profiler.h" |
| 21 | 21 |
| 22 namespace dart { | 22 namespace dart { |
| 23 | 23 |
| 24 #define VALIDATE_PTHREAD_RESULT(result) \ | 24 #define VALIDATE_PTHREAD_RESULT(result) \ |
| 25 if (result != 0) { \ | 25 if (result != 0) { \ |
| 26 const int kBufferSize = 1024; \ | 26 const int kBufferSize = 1024; \ |
| 27 char error_buf[kBufferSize]; \ | 27 char error_buf[kBufferSize]; \ |
| 28 NOT_IN_PRODUCT(Profiler::DumpStackTrace(true /* native_stack_trace */)); \ | 28 NOT_IN_PRODUCT(Profiler::DumpStackTrace(true /* native_stack_trace */)); \ |
| 29 FATAL2("pthread error: %d (%s)", result, \ | 29 FATAL2("pthread error: %d (%s)", result, \ |
| 30 Utils::StrError(result, error_buf, kBufferSize)); \ | 30 Utils::StrError(result, error_buf, kBufferSize)); \ |
| 31 } | 31 } |
| 32 | 32 |
| 33 | 33 |
| 34 #if defined(DEBUG) | 34 #if defined(DEBUG) |
| 35 #define ASSERT_PTHREAD_SUCCESS(result) VALIDATE_PTHREAD_RESULT(result) | 35 #define ASSERT_PTHREAD_SUCCESS(result) VALIDATE_PTHREAD_RESULT(result) |
| 36 #else | 36 #else |
| 37 // NOTE: This (currently) expands to a no-op. | 37 // NOTE: This (currently) expands to a no-op. |
| 38 #define ASSERT_PTHREAD_SUCCESS(result) ASSERT(result == 0) | 38 #define ASSERT_PTHREAD_SUCCESS(result) ASSERT(result == 0) |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 | 41 |
| 42 #ifdef DEBUG | 42 #ifdef DEBUG |
| 43 #define RETURN_ON_PTHREAD_FAILURE(result) \ | 43 #define RETURN_ON_PTHREAD_FAILURE(result) \ |
| 44 if (result != 0) { \ | 44 if (result != 0) { \ |
| 45 const int kBufferSize = 1024; \ | 45 const int kBufferSize = 1024; \ |
| 46 char error_buf[kBufferSize]; \ | 46 char error_buf[kBufferSize]; \ |
| 47 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", \ | 47 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", __FILE__, __LINE__, \ |
| 48 __FILE__, __LINE__, result, \ | 48 result, Utils::StrError(result, error_buf, kBufferSize)); \ |
| 49 Utils::StrError(result, error_buf, kBufferSize)); \ | 49 return result; \ |
| 50 return result; \ | |
| 51 } | 50 } |
| 52 #else | 51 #else |
| 53 #define RETURN_ON_PTHREAD_FAILURE(result) \ | 52 #define RETURN_ON_PTHREAD_FAILURE(result) \ |
| 54 if (result != 0) return result; | 53 if (result != 0) return result; |
| 55 #endif | 54 #endif |
| 56 | 55 |
| 57 | 56 |
| 58 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { | 57 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { |
| 59 int64_t secs = micros / kMicrosecondsPerSecond; | 58 int64_t secs = micros / kMicrosecondsPerSecond; |
| 60 int64_t nanos = | 59 int64_t nanos = |
| 61 (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond; | 60 (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond; |
| 62 int result = clock_gettime(CLOCK_MONOTONIC, ts); | 61 int result = clock_gettime(CLOCK_MONOTONIC, ts); |
| 63 ASSERT(result == 0); | 62 ASSERT(result == 0); |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 void Monitor::NotifyAll() { | 450 void Monitor::NotifyAll() { |
| 452 // When running with assertions enabled we track the owner. | 451 // When running with assertions enabled we track the owner. |
| 453 ASSERT(IsOwnedByCurrentThread()); | 452 ASSERT(IsOwnedByCurrentThread()); |
| 454 int result = pthread_cond_broadcast(data_.cond()); | 453 int result = pthread_cond_broadcast(data_.cond()); |
| 455 VALIDATE_PTHREAD_RESULT(result); | 454 VALIDATE_PTHREAD_RESULT(result); |
| 456 } | 455 } |
| 457 | 456 |
| 458 } // namespace dart | 457 } // namespace dart |
| 459 | 458 |
| 460 #endif // defined(TARGET_OS_LINUX) | 459 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |