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 "platform/thread.h" | 8 #include "platform/thread.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 RETURN_ON_PTHREAD_FAILURE(result); | 106 RETURN_ON_PTHREAD_FAILURE(result); |
107 | 107 |
108 result = pthread_attr_destroy(&attr); | 108 result = pthread_attr_destroy(&attr); |
109 RETURN_ON_PTHREAD_FAILURE(result); | 109 RETURN_ON_PTHREAD_FAILURE(result); |
110 | 110 |
111 return 0; | 111 return 0; |
112 } | 112 } |
113 | 113 |
114 | 114 |
115 ThreadLocalKey Thread::kUnsetThreadLocalKey = static_cast<pthread_key_t>(-1); | 115 ThreadLocalKey Thread::kUnsetThreadLocalKey = static_cast<pthread_key_t>(-1); |
116 | 116 ThreadId Thread::kInvalidThreadId = static_cast<ThreadId>(0); |
117 | 117 |
118 ThreadLocalKey Thread::CreateThreadLocal() { | 118 ThreadLocalKey Thread::CreateThreadLocal() { |
119 pthread_key_t key = kUnsetThreadLocalKey; | 119 pthread_key_t key = kUnsetThreadLocalKey; |
120 int result = pthread_key_create(&key, NULL); | 120 int result = pthread_key_create(&key, NULL); |
121 VALIDATE_PTHREAD_RESULT(result); | 121 VALIDATE_PTHREAD_RESULT(result); |
122 ASSERT(key != kUnsetThreadLocalKey); | 122 ASSERT(key != kUnsetThreadLocalKey); |
123 return key; | 123 return key; |
124 } | 124 } |
125 | 125 |
126 | 126 |
(...skipping 15 matching lines...) Expand all Loading... |
142 const int kStackSize = (128 * kWordSize * KB); | 142 const int kStackSize = (128 * kWordSize * KB); |
143 return kStackSize; | 143 return kStackSize; |
144 } | 144 } |
145 | 145 |
146 | 146 |
147 ThreadId Thread::GetCurrentThreadId() { | 147 ThreadId Thread::GetCurrentThreadId() { |
148 return pthread_self(); | 148 return pthread_self(); |
149 } | 149 } |
150 | 150 |
151 | 151 |
| 152 intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { |
| 153 ASSERT(sizeof(id) == sizeof(intptr_t)); |
| 154 return static_cast<intptr_t>(id); |
| 155 } |
| 156 |
| 157 |
| 158 bool Thread::Compare(ThreadId a, ThreadId b) { |
| 159 return pthread_equal(a, b) != 0; |
| 160 } |
| 161 |
| 162 |
152 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { | 163 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { |
153 ASSERT(thread_id == GetCurrentThreadId()); | 164 ASSERT(thread_id == GetCurrentThreadId()); |
154 ASSERT(cpu_usage != NULL); | 165 ASSERT(cpu_usage != NULL); |
155 struct timespec ts; | 166 struct timespec ts; |
156 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); | 167 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); |
157 ASSERT(r == 0); | 168 ASSERT(r == 0); |
158 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / | 169 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / |
159 kNanosecondsPerMicrosecond; | 170 kNanosecondsPerMicrosecond; |
160 } | 171 } |
161 | 172 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 312 |
302 void Monitor::NotifyAll() { | 313 void Monitor::NotifyAll() { |
303 // TODO(iposva): Do we need to track lock owners? | 314 // TODO(iposva): Do we need to track lock owners? |
304 int result = pthread_cond_broadcast(data_.cond()); | 315 int result = pthread_cond_broadcast(data_.cond()); |
305 VALIDATE_PTHREAD_RESULT(result); | 316 VALIDATE_PTHREAD_RESULT(result); |
306 } | 317 } |
307 | 318 |
308 } // namespace dart | 319 } // namespace dart |
309 | 320 |
310 #endif // defined(TARGET_OS_ANDROID) | 321 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |