Chromium Code Reviews| Index: runtime/platform/thread_linux.cc |
| diff --git a/runtime/platform/thread_linux.cc b/runtime/platform/thread_linux.cc |
| index acb78c71ed5423a0daeebcde32bb5c959b74adca..85bac0a3359c91c631e33c0d8daba71d09f0cdab 100644 |
| --- a/runtime/platform/thread_linux.cc |
| +++ b/runtime/platform/thread_linux.cc |
| @@ -8,6 +8,7 @@ |
| #include "platform/thread.h" |
| #include <errno.h> // NOLINT |
| +#include <sys/resource.h> // NOLINT |
| #include <sys/time.h> // NOLINT |
| #include "platform/assert.h" |
| @@ -54,6 +55,21 @@ static void ComputeTimeSpec(struct timespec* ts, int64_t millis) { |
| } |
| +static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { |
| + int64_t secs = micros / kMicrosecondsPerSecond; |
| + int64_t nanos = |
| + (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond; |
| + int result = clock_gettime(CLOCK_MONOTONIC, ts); |
| + ASSERT(result == 0); |
| + ts->tv_sec += secs; |
| + ts->tv_nsec += nanos; |
| + if (ts->tv_nsec >= kNanosecondsPerSecond) { |
| + ts->tv_sec += 1; |
| + ts->tv_nsec -= kNanosecondsPerSecond; |
| + } |
|
siva
2013/10/28 05:19:21
This seems a repeat of the code above why not repl
Cutch
2013/11/04 20:36:05
Done.
|
| +} |
| + |
| + |
| class ThreadStartData { |
| public: |
| ThreadStartData(Thread::ThreadStartFunction function, |
| @@ -144,6 +160,21 @@ intptr_t Thread::GetMaxStackSize() { |
| } |
| +ThreadId Thread::GetCurrentThreadId() { |
| + return pthread_self(); |
| +} |
| + |
| + |
| +void Thread::GetThreadCPUUsage(int64_t* cpu_usage) { |
| + ASSERT(cpu_usage != NULL); |
| + struct timespec ts; |
| + int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); |
| + ASSERT(r == 0); |
| + *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / |
| + kNanosecondsPerMicrosecond; |
| +} |
| + |
| + |
| Mutex::Mutex() { |
| pthread_mutexattr_t attr; |
| int result = pthread_mutexattr_init(&attr); |
| @@ -274,6 +305,26 @@ Monitor::WaitResult Monitor::Wait(int64_t millis) { |
| } |
| +Monitor::WaitResult Monitor::WaitMicros(int64_t micros) { |
| + // TODO(iposva): Do we need to track lock owners? |
| + Monitor::WaitResult retval = kNotified; |
| + if (micros == 0) { |
|
siva
2013/10/28 05:19:21
should be if (micros == dart::Monitor::kNoTimeout)
Cutch
2013/11/04 20:36:05
Done.
|
| + // Wait forever. |
| + int result = pthread_cond_wait(data_.cond(), data_.mutex()); |
| + VALIDATE_PTHREAD_RESULT(result); |
| + } else { |
| + struct timespec ts; |
| + ComputeTimeSpecMicros(&ts, micros); |
| + int result = pthread_cond_timedwait(data_.cond(), data_.mutex(), &ts); |
| + ASSERT((result == 0) || (result == ETIMEDOUT)); |
| + if (result == ETIMEDOUT) { |
| + retval = kTimedOut; |
| + } |
|
siva
2013/10/28 05:19:21
else {
VALIDATE_PTHREAD_RESULT(result); ?
}
Cutch
2013/11/04 20:36:05
The above ASSERT((result == 0) || (result == ETIME
|
| + } |
| + return retval; |
| +} |
| + |
| + |
| void Monitor::Notify() { |
| // TODO(iposva): Do we need to track lock owners? |
| int result = pthread_cond_signal(data_.cond()); |