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