| 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 #include "bin/thread_android.h" |
| 10 | 10 |
| 11 #include <errno.h> // NOLINT | 11 #include <errno.h> // NOLINT |
| 12 #include <sys/time.h> // NOLINT | 12 #include <sys/time.h> // NOLINT |
| 13 | 13 |
| 14 #include "platform/assert.h" | 14 #include "platform/assert.h" |
| 15 #include "platform/utils.h" | 15 #include "platform/utils.h" |
| 16 | 16 |
| 17 namespace dart { | 17 namespace dart { |
| 18 namespace bin { | 18 namespace bin { |
| 19 | 19 |
| 20 #define VALIDATE_PTHREAD_RESULT(result) \ | 20 #define VALIDATE_PTHREAD_RESULT(result) \ |
| 21 if (result != 0) { \ | 21 if (result != 0) { \ |
| 22 const int kBufferSize = 1024; \ | 22 const int kBufferSize = 1024; \ |
| 23 char error_message[kBufferSize]; \ | 23 char error_message[kBufferSize]; \ |
| 24 Utils::StrError(result, error_message, kBufferSize); \ | 24 Utils::StrError(result, error_message, kBufferSize); \ |
| 25 FATAL2("pthread error: %d (%s)", result, error_message); \ | 25 FATAL2("pthread error: %d (%s)", result, error_message); \ |
| 26 } | 26 } |
| 27 | 27 |
| 28 | 28 |
| 29 #ifdef DEBUG | 29 #ifdef DEBUG |
| 30 #define RETURN_ON_PTHREAD_FAILURE(result) \ | 30 #define RETURN_ON_PTHREAD_FAILURE(result) \ |
| 31 if (result != 0) { \ | 31 if (result != 0) { \ |
| 32 const int kBufferSize = 1024; \ | 32 const int kBufferSize = 1024; \ |
| 33 char error_message[kBufferSize]; \ | 33 char error_message[kBufferSize]; \ |
| 34 Utils::StrError(result, error_message, kBufferSize); \ | 34 Utils::StrError(result, error_message, kBufferSize); \ |
| 35 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", \ | 35 fprintf(stderr, "%s:%d: pthread error: %d (%s)\n", __FILE__, __LINE__, \ |
| 36 __FILE__, __LINE__, result, error_message); \ | 36 result, error_message); \ |
| 37 return result; \ | 37 return result; \ |
| 38 } | 38 } |
| 39 #else | 39 #else |
| 40 #define RETURN_ON_PTHREAD_FAILURE(result) \ | 40 #define RETURN_ON_PTHREAD_FAILURE(result) \ |
| 41 if (result != 0) { \ | 41 if (result != 0) { \ |
| 42 return result; \ | 42 return result; \ |
| 43 } | 43 } |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 | 46 |
| 47 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { | 47 static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { |
| 48 struct timeval tv; | 48 struct timeval tv; |
| 49 int64_t secs = micros / kMicrosecondsPerSecond; | 49 int64_t secs = micros / kMicrosecondsPerSecond; |
| 50 int64_t remaining_micros = (micros - (secs * kMicrosecondsPerSecond)); | 50 int64_t remaining_micros = (micros - (secs * kMicrosecondsPerSecond)); |
| 51 int result = gettimeofday(&tv, NULL); | 51 int result = gettimeofday(&tv, NULL); |
| 52 ASSERT(result == 0); | 52 ASSERT(result == 0); |
| 53 ts->tv_sec = tv.tv_sec + secs; | 53 ts->tv_sec = tv.tv_sec + secs; |
| 54 ts->tv_nsec = (tv.tv_usec + remaining_micros) * kNanosecondsPerMicrosecond; | 54 ts->tv_nsec = (tv.tv_usec + remaining_micros) * kNanosecondsPerMicrosecond; |
| 55 if (ts->tv_nsec >= kNanosecondsPerSecond) { | 55 if (ts->tv_nsec >= kNanosecondsPerSecond) { |
| 56 ts->tv_sec += 1; | 56 ts->tv_sec += 1; |
| 57 ts->tv_nsec -= kNanosecondsPerSecond; | 57 ts->tv_nsec -= kNanosecondsPerSecond; |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 | 61 |
| 62 class ThreadStartData { | 62 class ThreadStartData { |
| 63 public: | 63 public: |
| 64 ThreadStartData(Thread::ThreadStartFunction function, | 64 ThreadStartData(Thread::ThreadStartFunction function, uword parameter) |
| 65 uword parameter) | |
| 66 : function_(function), parameter_(parameter) {} | 65 : function_(function), parameter_(parameter) {} |
| 67 | 66 |
| 68 Thread::ThreadStartFunction function() const { return function_; } | 67 Thread::ThreadStartFunction function() const { return function_; } |
| 69 uword parameter() const { return parameter_; } | 68 uword parameter() const { return parameter_; } |
| 70 | 69 |
| 71 private: | 70 private: |
| 72 Thread::ThreadStartFunction function_; | 71 Thread::ThreadStartFunction function_; |
| 73 uword parameter_; | 72 uword parameter_; |
| 74 | 73 |
| 75 DISALLOW_COPY_AND_ASSIGN(ThreadStartData); | 74 DISALLOW_COPY_AND_ASSIGN(ThreadStartData); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 void Monitor::NotifyAll() { | 323 void Monitor::NotifyAll() { |
| 325 // TODO(iposva): Do we need to track lock owners? | 324 // TODO(iposva): Do we need to track lock owners? |
| 326 int result = pthread_cond_broadcast(data_.cond()); | 325 int result = pthread_cond_broadcast(data_.cond()); |
| 327 VALIDATE_PTHREAD_RESULT(result); | 326 VALIDATE_PTHREAD_RESULT(result); |
| 328 } | 327 } |
| 329 | 328 |
| 330 } // namespace bin | 329 } // namespace bin |
| 331 } // namespace dart | 330 } // namespace dart |
| 332 | 331 |
| 333 #endif // defined(TARGET_OS_ANDROID) | 332 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |