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 #if defined(TARGET_OS_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
7 | 7 |
8 #include "vm/os_thread.h" | 8 #include "vm/os_thread.h" |
9 | 9 |
10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 | 94 |
95 return NULL; | 95 return NULL; |
96 } | 96 } |
97 | 97 |
98 | 98 |
99 int OSThread::Start(ThreadStartFunction function, uword parameter) { | 99 int OSThread::Start(ThreadStartFunction function, uword parameter) { |
100 pthread_attr_t attr; | 100 pthread_attr_t attr; |
101 int result = pthread_attr_init(&attr); | 101 int result = pthread_attr_init(&attr); |
102 RETURN_ON_PTHREAD_FAILURE(result); | 102 RETURN_ON_PTHREAD_FAILURE(result); |
103 | 103 |
104 result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | |
105 RETURN_ON_PTHREAD_FAILURE(result); | |
106 | |
107 result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); | 104 result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); |
108 RETURN_ON_PTHREAD_FAILURE(result); | 105 RETURN_ON_PTHREAD_FAILURE(result); |
109 | 106 |
110 ThreadStartData* data = new ThreadStartData(function, parameter); | 107 ThreadStartData* data = new ThreadStartData(function, parameter); |
111 | 108 |
112 pthread_t tid; | 109 pthread_t tid; |
113 result = pthread_create(&tid, &attr, ThreadStart, data); | 110 result = pthread_create(&tid, &attr, ThreadStart, data); |
114 RETURN_ON_PTHREAD_FAILURE(result); | 111 RETURN_ON_PTHREAD_FAILURE(result); |
115 | 112 |
116 result = pthread_attr_destroy(&attr); | 113 result = pthread_attr_destroy(&attr); |
(...skipping 29 matching lines...) Expand all Loading... | |
146 VALIDATE_PTHREAD_RESULT(result); | 143 VALIDATE_PTHREAD_RESULT(result); |
147 } | 144 } |
148 | 145 |
149 | 146 |
150 intptr_t OSThread::GetMaxStackSize() { | 147 intptr_t OSThread::GetMaxStackSize() { |
151 const int kStackSize = (128 * kWordSize * KB); | 148 const int kStackSize = (128 * kWordSize * KB); |
152 return kStackSize; | 149 return kStackSize; |
153 } | 150 } |
154 | 151 |
155 | 152 |
156 ThreadId OSThread::GetCurrentThreadId() { | 153 ThreadId OSThread::GetCurrentThreadId() { |
Ivan Posva
2015/08/17 13:35:52
This is currently used by the profiler and relies
zra
2015/08/18 06:23:14
Restored gettid() here, and added a GetCurrentThre
| |
157 return gettid(); | 154 return pthread_self(); |
158 } | 155 } |
159 | 156 |
160 | 157 |
161 bool OSThread::Join(ThreadId id) { | 158 bool OSThread::Join(ThreadId id) { |
162 return false; | 159 return pthread_join(id, NULL) == 0; |
163 } | 160 } |
164 | 161 |
165 | 162 |
166 intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { | 163 intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { |
167 ASSERT(sizeof(id) == sizeof(intptr_t)); | 164 ASSERT(sizeof(id) == sizeof(intptr_t)); |
168 return static_cast<intptr_t>(id); | 165 return static_cast<intptr_t>(id); |
169 } | 166 } |
170 | 167 |
171 | 168 |
172 bool OSThread::Compare(ThreadId a, ThreadId b) { | 169 bool OSThread::Compare(ThreadId a, ThreadId b) { |
173 return a == b; | 170 return pthread_equal(a, b) != 0; |
174 } | 171 } |
175 | 172 |
176 | 173 |
177 void OSThread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { | 174 void OSThread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { |
178 ASSERT(thread_id == GetCurrentThreadId()); | 175 ASSERT(thread_id == GetCurrentThreadId()); |
179 ASSERT(cpu_usage != NULL); | 176 ASSERT(cpu_usage != NULL); |
180 struct timespec ts; | 177 struct timespec ts; |
181 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); | 178 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); |
182 ASSERT(r == 0); | 179 ASSERT(r == 0); |
183 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / | 180 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 | 343 |
347 void Monitor::NotifyAll() { | 344 void Monitor::NotifyAll() { |
348 // TODO(iposva): Do we need to track lock owners? | 345 // TODO(iposva): Do we need to track lock owners? |
349 int result = pthread_cond_broadcast(data_.cond()); | 346 int result = pthread_cond_broadcast(data_.cond()); |
350 VALIDATE_PTHREAD_RESULT(result); | 347 VALIDATE_PTHREAD_RESULT(result); |
351 } | 348 } |
352 | 349 |
353 } // namespace dart | 350 } // namespace dart |
354 | 351 |
355 #endif // defined(TARGET_OS_ANDROID) | 352 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |