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 <errno.h> | 7 #include <errno.h> |
8 #include <sys/time.h> | 8 #include <sys/time.h> |
9 | 9 |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 result = pthread_create(&tid, &attr, ThreadStart, data); | 96 result = pthread_create(&tid, &attr, ThreadStart, data); |
97 RETURN_ON_PTHREAD_FAILURE(result); | 97 RETURN_ON_PTHREAD_FAILURE(result); |
98 | 98 |
99 result = pthread_attr_destroy(&attr); | 99 result = pthread_attr_destroy(&attr); |
100 RETURN_ON_PTHREAD_FAILURE(result); | 100 RETURN_ON_PTHREAD_FAILURE(result); |
101 | 101 |
102 return 0; | 102 return 0; |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 ThreadLocalKey Thread::kInvalidThreadLocal = static_cast<pthread_key_t>(-1); | |
107 | |
108 | |
109 ThreadLocalKey Thread::CreateThreadLocal() { | |
110 pthread_key_t key = kInvalidThreadLocal; | |
111 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.
| |
112 VALIDATE_PTHREAD_RESULT(result); | |
113 return key; | |
114 } | |
115 | |
116 | |
117 void Thread::DeleteThreadLocal(ThreadLocalKey key) { | |
118 ASSERT(key != kInvalidThreadLocal); | |
119 int result = pthread_key_delete(key); | |
120 VALIDATE_PTHREAD_RESULT(result); | |
121 } | |
122 | |
123 | |
124 uword Thread::GetThreadLocal(ThreadLocalKey key) { | |
125 ASSERT(key != kInvalidThreadLocal); | |
126 return reinterpret_cast<uword>(pthread_getspecific(key)); | |
127 } | |
siva
2012/02/06 19:29:37
Can this be defined in the header file so that it
Søren Gjesse
2012/02/07 09:13:59
Added a class ThreadInlineImpl to platform specifi
| |
128 | |
129 | |
130 void Thread::SetThreadLocal(ThreadLocalKey key, uword value) { | |
131 ASSERT(key != kInvalidThreadLocal); | |
132 int result = pthread_setspecific(key, reinterpret_cast<void*>(value)); | |
133 VALIDATE_PTHREAD_RESULT(result); | |
134 } | |
135 | |
136 | |
106 Mutex::Mutex() { | 137 Mutex::Mutex() { |
107 pthread_mutexattr_t attr; | 138 pthread_mutexattr_t attr; |
108 int result = pthread_mutexattr_init(&attr); | 139 int result = pthread_mutexattr_init(&attr); |
109 VALIDATE_PTHREAD_RESULT(result); | 140 VALIDATE_PTHREAD_RESULT(result); |
110 | 141 |
111 #if defined(DEBUG) | 142 #if defined(DEBUG) |
112 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); | 143 result = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK); |
113 VALIDATE_PTHREAD_RESULT(result); | 144 VALIDATE_PTHREAD_RESULT(result); |
114 #endif // defined(DEBUG) | 145 #endif // defined(DEBUG) |
115 | 146 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 } | 271 } |
241 | 272 |
242 | 273 |
243 void Monitor::NotifyAll() { | 274 void Monitor::NotifyAll() { |
244 // TODO(iposva): Do we need to track lock owners? | 275 // TODO(iposva): Do we need to track lock owners? |
245 int result = pthread_cond_broadcast(data_.cond()); | 276 int result = pthread_cond_broadcast(data_.cond()); |
246 VALIDATE_PTHREAD_RESULT(result); | 277 VALIDATE_PTHREAD_RESULT(result); |
247 } | 278 } |
248 | 279 |
249 } // namespace dart | 280 } // namespace dart |
OLD | NEW |