| 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_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
| 7 | 7 |
| 8 #include "vm/os_thread.h" | 8 #include "vm/os_thread.h" |
| 9 | 9 |
| 10 #include <sys/errno.h> // NOLINT | 10 #include <sys/errno.h> // NOLINT |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 87 |
| 88 return NULL; | 88 return NULL; |
| 89 } | 89 } |
| 90 | 90 |
| 91 | 91 |
| 92 int OSThread::Start(ThreadStartFunction function, uword parameter) { | 92 int OSThread::Start(ThreadStartFunction function, uword parameter) { |
| 93 pthread_attr_t attr; | 93 pthread_attr_t attr; |
| 94 int result = pthread_attr_init(&attr); | 94 int result = pthread_attr_init(&attr); |
| 95 RETURN_ON_PTHREAD_FAILURE(result); | 95 RETURN_ON_PTHREAD_FAILURE(result); |
| 96 | 96 |
| 97 result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | |
| 98 RETURN_ON_PTHREAD_FAILURE(result); | |
| 99 | |
| 100 result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); | 97 result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); |
| 101 RETURN_ON_PTHREAD_FAILURE(result); | 98 RETURN_ON_PTHREAD_FAILURE(result); |
| 102 | 99 |
| 103 ThreadStartData* data = new ThreadStartData(function, parameter); | 100 ThreadStartData* data = new ThreadStartData(function, parameter); |
| 104 | 101 |
| 105 pthread_t tid; | 102 pthread_t tid; |
| 106 result = pthread_create(&tid, &attr, ThreadStart, data); | 103 result = pthread_create(&tid, &attr, ThreadStart, data); |
| 107 RETURN_ON_PTHREAD_FAILURE(result); | 104 RETURN_ON_PTHREAD_FAILURE(result); |
| 108 | 105 |
| 109 result = pthread_attr_destroy(&attr); | 106 result = pthread_attr_destroy(&attr); |
| 110 RETURN_ON_PTHREAD_FAILURE(result); | 107 RETURN_ON_PTHREAD_FAILURE(result); |
| 111 | 108 |
| 112 return 0; | 109 return 0; |
| 113 } | 110 } |
| 114 | 111 |
| 115 | 112 |
| 116 ThreadLocalKey OSThread::kUnsetThreadLocalKey = | 113 ThreadLocalKey OSThread::kUnsetThreadLocalKey = |
| 117 static_cast<pthread_key_t>(-1); | 114 static_cast<pthread_key_t>(-1); |
| 118 ThreadId OSThread::kInvalidThreadId = reinterpret_cast<ThreadId>(NULL); | 115 ThreadId OSThread::kInvalidThreadId = reinterpret_cast<ThreadId>(NULL); |
| 116 ThreadJoinId OSThread::kInvalidThreadJoinId = |
| 117 reinterpret_cast<ThreadJoinId>(NULL); |
| 119 | 118 |
| 120 ThreadLocalKey OSThread::CreateThreadLocal(ThreadDestructor destructor) { | 119 ThreadLocalKey OSThread::CreateThreadLocal(ThreadDestructor destructor) { |
| 121 pthread_key_t key = kUnsetThreadLocalKey; | 120 pthread_key_t key = kUnsetThreadLocalKey; |
| 122 int result = pthread_key_create(&key, destructor); | 121 int result = pthread_key_create(&key, destructor); |
| 123 VALIDATE_PTHREAD_RESULT(result); | 122 VALIDATE_PTHREAD_RESULT(result); |
| 124 ASSERT(key != kUnsetThreadLocalKey); | 123 ASSERT(key != kUnsetThreadLocalKey); |
| 125 return key; | 124 return key; |
| 126 } | 125 } |
| 127 | 126 |
| 128 | 127 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 144 const int kStackSize = (128 * kWordSize * KB); | 143 const int kStackSize = (128 * kWordSize * KB); |
| 145 return kStackSize; | 144 return kStackSize; |
| 146 } | 145 } |
| 147 | 146 |
| 148 | 147 |
| 149 ThreadId OSThread::GetCurrentThreadId() { | 148 ThreadId OSThread::GetCurrentThreadId() { |
| 150 return pthread_self(); | 149 return pthread_self(); |
| 151 } | 150 } |
| 152 | 151 |
| 153 | 152 |
| 154 bool OSThread::Join(ThreadId id) { | 153 ThreadJoinId OSThread::GetCurrentThreadJoinId() { |
| 155 return false; | 154 return pthread_self(); |
| 156 } | 155 } |
| 157 | 156 |
| 158 | 157 |
| 158 void OSThread::Join(ThreadJoinId id) { |
| 159 ASSERT(pthread_join(id, NULL) == 0); |
| 160 } |
| 161 |
| 162 |
| 159 intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { | 163 intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { |
| 160 ASSERT(sizeof(id) == sizeof(intptr_t)); | 164 ASSERT(sizeof(id) == sizeof(intptr_t)); |
| 161 return reinterpret_cast<intptr_t>(id); | 165 return reinterpret_cast<intptr_t>(id); |
| 162 } | 166 } |
| 163 | 167 |
| 164 | 168 |
| 165 ThreadId OSThread::ThreadIdFromIntPtr(intptr_t id) { | 169 ThreadId OSThread::ThreadIdFromIntPtr(intptr_t id) { |
| 166 return reinterpret_cast<ThreadId>(id); | 170 return reinterpret_cast<ThreadId>(id); |
| 167 } | 171 } |
| 168 | 172 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 364 |
| 361 void Monitor::NotifyAll() { | 365 void Monitor::NotifyAll() { |
| 362 // TODO(iposva): Do we need to track lock owners? | 366 // TODO(iposva): Do we need to track lock owners? |
| 363 int result = pthread_cond_broadcast(data_.cond()); | 367 int result = pthread_cond_broadcast(data_.cond()); |
| 364 VALIDATE_PTHREAD_RESULT(result); | 368 VALIDATE_PTHREAD_RESULT(result); |
| 365 } | 369 } |
| 366 | 370 |
| 367 } // namespace dart | 371 } // namespace dart |
| 368 | 372 |
| 369 #endif // defined(TARGET_OS_MACOS) | 373 #endif // defined(TARGET_OS_MACOS) |
| OLD | NEW |