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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 return NULL; | 96 return NULL; |
97 } | 97 } |
98 | 98 |
99 | 99 |
100 int OSThread::Start(ThreadStartFunction function, uword parameter) { | 100 int OSThread::Start(ThreadStartFunction function, uword parameter) { |
101 pthread_attr_t attr; | 101 pthread_attr_t attr; |
102 int result = pthread_attr_init(&attr); | 102 int result = pthread_attr_init(&attr); |
103 RETURN_ON_PTHREAD_FAILURE(result); | 103 RETURN_ON_PTHREAD_FAILURE(result); |
104 | 104 |
105 result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | |
106 RETURN_ON_PTHREAD_FAILURE(result); | |
107 | |
108 result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); | 105 result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); |
109 RETURN_ON_PTHREAD_FAILURE(result); | 106 RETURN_ON_PTHREAD_FAILURE(result); |
110 | 107 |
111 ThreadStartData* data = new ThreadStartData(function, parameter); | 108 ThreadStartData* data = new ThreadStartData(function, parameter); |
112 | 109 |
113 pthread_t tid; | 110 pthread_t tid; |
114 result = pthread_create(&tid, &attr, ThreadStart, data); | 111 result = pthread_create(&tid, &attr, ThreadStart, data); |
115 RETURN_ON_PTHREAD_FAILURE(result); | 112 RETURN_ON_PTHREAD_FAILURE(result); |
116 | 113 |
117 result = pthread_attr_destroy(&attr); | 114 result = pthread_attr_destroy(&attr); |
118 RETURN_ON_PTHREAD_FAILURE(result); | 115 RETURN_ON_PTHREAD_FAILURE(result); |
119 | 116 |
120 return 0; | 117 return 0; |
121 } | 118 } |
122 | 119 |
123 | 120 |
124 ThreadLocalKey OSThread::kUnsetThreadLocalKey = | 121 ThreadLocalKey OSThread::kUnsetThreadLocalKey = |
125 static_cast<pthread_key_t>(-1); | 122 static_cast<pthread_key_t>(-1); |
126 ThreadId OSThread::kInvalidThreadId = static_cast<ThreadId>(0); | 123 ThreadId OSThread::kInvalidThreadId = static_cast<ThreadId>(0); |
| 124 ThreadJoinId OSThread::kInvalidThreadJoinId = static_cast<ThreadJoinId>(0); |
127 | 125 |
128 ThreadLocalKey OSThread::CreateThreadLocal(ThreadDestructor destructor) { | 126 ThreadLocalKey OSThread::CreateThreadLocal(ThreadDestructor destructor) { |
129 pthread_key_t key = kUnsetThreadLocalKey; | 127 pthread_key_t key = kUnsetThreadLocalKey; |
130 int result = pthread_key_create(&key, destructor); | 128 int result = pthread_key_create(&key, destructor); |
131 VALIDATE_PTHREAD_RESULT(result); | 129 VALIDATE_PTHREAD_RESULT(result); |
132 ASSERT(key != kUnsetThreadLocalKey); | 130 ASSERT(key != kUnsetThreadLocalKey); |
133 return key; | 131 return key; |
134 } | 132 } |
135 | 133 |
136 | 134 |
(...skipping 15 matching lines...) Expand all Loading... |
152 const int kStackSize = (128 * kWordSize * KB); | 150 const int kStackSize = (128 * kWordSize * KB); |
153 return kStackSize; | 151 return kStackSize; |
154 } | 152 } |
155 | 153 |
156 | 154 |
157 ThreadId OSThread::GetCurrentThreadId() { | 155 ThreadId OSThread::GetCurrentThreadId() { |
158 return pthread_self(); | 156 return pthread_self(); |
159 } | 157 } |
160 | 158 |
161 | 159 |
162 bool OSThread::Join(ThreadId id) { | 160 ThreadJoinId OSThread::GetCurrentThreadJoinId() { |
163 return false; | 161 return pthread_self(); |
164 } | 162 } |
165 | 163 |
166 | 164 |
| 165 void OSThread::Join(ThreadJoinId id) { |
| 166 ASSERT(pthread_join(id, NULL) == 0); |
| 167 } |
| 168 |
| 169 |
167 intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { | 170 intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { |
168 ASSERT(sizeof(id) == sizeof(intptr_t)); | 171 ASSERT(sizeof(id) == sizeof(intptr_t)); |
169 return static_cast<intptr_t>(id); | 172 return static_cast<intptr_t>(id); |
170 } | 173 } |
171 | 174 |
172 | 175 |
173 ThreadId OSThread::ThreadIdFromIntPtr(intptr_t id) { | 176 ThreadId OSThread::ThreadIdFromIntPtr(intptr_t id) { |
174 return static_cast<ThreadId>(id); | 177 return static_cast<ThreadId>(id); |
175 } | 178 } |
176 | 179 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 358 |
356 void Monitor::NotifyAll() { | 359 void Monitor::NotifyAll() { |
357 // TODO(iposva): Do we need to track lock owners? | 360 // TODO(iposva): Do we need to track lock owners? |
358 int result = pthread_cond_broadcast(data_.cond()); | 361 int result = pthread_cond_broadcast(data_.cond()); |
359 VALIDATE_PTHREAD_RESULT(result); | 362 VALIDATE_PTHREAD_RESULT(result); |
360 } | 363 } |
361 | 364 |
362 } // namespace dart | 365 } // namespace dart |
363 | 366 |
364 #endif // defined(TARGET_OS_LINUX) | 367 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |