Chromium Code Reviews| 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/thread.h" | 5 #include "platform/thread.h" |
| 6 | 6 |
| 7 #include <sys/errno.h> | 7 #include <sys/errno.h> |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 | 10 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 result = pthread_create(&tid, &attr, ThreadStart, data); | 80 result = pthread_create(&tid, &attr, ThreadStart, data); |
| 81 RETURN_ON_PTHREAD_FAILURE(result); | 81 RETURN_ON_PTHREAD_FAILURE(result); |
| 82 | 82 |
| 83 result = pthread_attr_destroy(&attr); | 83 result = pthread_attr_destroy(&attr); |
| 84 RETURN_ON_PTHREAD_FAILURE(result); | 84 RETURN_ON_PTHREAD_FAILURE(result); |
| 85 | 85 |
| 86 return 0; | 86 return 0; |
| 87 } | 87 } |
| 88 | 88 |
| 89 | 89 |
| 90 ThreadLocalKey Thread::kInvalidThreadLocal = static_cast<pthread_key_t>(-1); | |
| 91 | |
| 92 | |
| 93 ThreadLocalKey Thread::CreateThreadLocal() { | |
| 94 pthread_key_t key = kInvalidThreadLocal; | |
| 95 int result = pthread_key_create(&key, NULL); | |
|
siva
2012/02/06 19:29:37
ASSERT(key != kInvalidThreadLocal);
Søren Gjesse
2012/02/07 09:13:59
Done.
| |
| 96 VALIDATE_PTHREAD_RESULT(result); | |
| 97 return key; | |
| 98 } | |
| 99 | |
| 100 | |
| 101 void Thread::DeleteThreadLocal(ThreadLocalKey key) { | |
| 102 ASSERT(key != kInvalidThreadLocal); | |
| 103 int result = pthread_key_delete(key); | |
| 104 VALIDATE_PTHREAD_RESULT(result); | |
| 105 } | |
| 106 | |
| 107 | |
| 108 uword Thread::GetThreadLocal(ThreadLocalKey key) { | |
| 109 ASSERT(key != kInvalidThreadLocal); | |
| 110 return reinterpret_cast<uword>(pthread_getspecific(key)); | |
| 111 } | |
|
siva
2012/02/06 19:29:37
Inline this method in the header so that there is
Søren Gjesse
2012/02/07 09:13:59
Done.
| |
| 112 | |
| 113 | |
| 114 void Thread::SetThreadLocal(ThreadLocalKey key, uword value) { | |
| 115 ASSERT(key != kInvalidThreadLocal); | |
| 116 int result = pthread_setspecific(key, reinterpret_cast<void*>(value)); | |
| 117 VALIDATE_PTHREAD_RESULT(result); | |
| 118 } | |
| 119 | |
| 120 | |
| 90 Mutex::Mutex() { | 121 Mutex::Mutex() { |
| 91 pthread_mutexattr_t attr; | 122 pthread_mutexattr_t attr; |
| 92 int result = pthread_mutexattr_init(&attr); | 123 int result = pthread_mutexattr_init(&attr); |
| 93 VALIDATE_PTHREAD_RESULT(result); | 124 VALIDATE_PTHREAD_RESULT(result); |
| 94 | 125 |
| 95 #if defined(DEBUG) | 126 #if defined(DEBUG) |
| 96 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); | 127 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); |
| 97 VALIDATE_PTHREAD_RESULT(result); | 128 VALIDATE_PTHREAD_RESULT(result); |
| 98 #endif // defined(DEBUG) | 129 #endif // defined(DEBUG) |
| 99 | 130 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 } | 250 } |
| 220 | 251 |
| 221 | 252 |
| 222 void Monitor::NotifyAll() { | 253 void Monitor::NotifyAll() { |
| 223 // TODO(iposva): Do we need to track lock owners? | 254 // TODO(iposva): Do we need to track lock owners? |
| 224 int result = pthread_cond_broadcast(data_.cond()); | 255 int result = pthread_cond_broadcast(data_.cond()); |
| 225 VALIDATE_PTHREAD_RESULT(result); | 256 VALIDATE_PTHREAD_RESULT(result); |
| 226 } | 257 } |
| 227 | 258 |
| 228 } // namespace dart | 259 } // namespace dart |
| OLD | NEW |