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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 ASSERT(thread_id == GetCurrentThreadId()); | 206 ASSERT(thread_id == GetCurrentThreadId()); |
207 ASSERT(cpu_usage != NULL); | 207 ASSERT(cpu_usage != NULL); |
208 struct timespec ts; | 208 struct timespec ts; |
209 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); | 209 int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); |
210 ASSERT(r == 0); | 210 ASSERT(r == 0); |
211 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / | 211 *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) / |
212 kNanosecondsPerMicrosecond; | 212 kNanosecondsPerMicrosecond; |
213 } | 213 } |
214 | 214 |
215 | 215 |
216 Mutex::Mutex() { | 216 Mutex::Mutex(bool recursive) { |
217 pthread_mutexattr_t attr; | 217 pthread_mutexattr_t attr; |
218 int result = pthread_mutexattr_init(&attr); | 218 int result = pthread_mutexattr_init(&attr); |
219 VALIDATE_PTHREAD_RESULT(result); | 219 VALIDATE_PTHREAD_RESULT(result); |
220 | 220 |
221 #if defined(DEBUG) | 221 #if defined(DEBUG) |
222 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); | 222 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); |
223 VALIDATE_PTHREAD_RESULT(result); | 223 VALIDATE_PTHREAD_RESULT(result); |
224 #endif // defined(DEBUG) | 224 #endif // defined(DEBUG) |
225 | 225 |
| 226 if (recursive) { |
| 227 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); |
| 228 VALIDATE_PTHREAD_RESULT(result); |
| 229 } |
| 230 |
226 result = pthread_mutex_init(data_.mutex(), &attr); | 231 result = pthread_mutex_init(data_.mutex(), &attr); |
227 // Verify that creating a pthread_mutex succeeded. | 232 // Verify that creating a pthread_mutex succeeded. |
228 VALIDATE_PTHREAD_RESULT(result); | 233 VALIDATE_PTHREAD_RESULT(result); |
229 | 234 |
230 result = pthread_mutexattr_destroy(&attr); | 235 result = pthread_mutexattr_destroy(&attr); |
231 VALIDATE_PTHREAD_RESULT(result); | 236 VALIDATE_PTHREAD_RESULT(result); |
232 | 237 |
233 #if defined(DEBUG) | 238 #if defined(DEBUG) |
234 // When running with assertions enabled we track the owner. | 239 // When running with assertions enabled we track the owner. |
235 owner_ = OSThread::kInvalidThreadId; | 240 owner_ = OSThread::kInvalidThreadId; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 void Monitor::NotifyAll() { | 418 void Monitor::NotifyAll() { |
414 // When running with assertions enabled we track the owner. | 419 // When running with assertions enabled we track the owner. |
415 ASSERT(IsOwnedByCurrentThread()); | 420 ASSERT(IsOwnedByCurrentThread()); |
416 int result = pthread_cond_broadcast(data_.cond()); | 421 int result = pthread_cond_broadcast(data_.cond()); |
417 VALIDATE_PTHREAD_RESULT(result); | 422 VALIDATE_PTHREAD_RESULT(result); |
418 } | 423 } |
419 | 424 |
420 } // namespace dart | 425 } // namespace dart |
421 | 426 |
422 #endif // defined(TARGET_OS_LINUX) | 427 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |