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" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_MACOS) | 6 #if defined(TARGET_OS_MACOS) |
7 | 7 |
8 #include "platform/thread.h" | 8 #include "platform/thread.h" |
9 | 9 |
10 #include <sys/errno.h> // NOLINT | 10 #include <sys/errno.h> // NOLINT |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 RETURN_ON_PTHREAD_FAILURE(result); | 99 RETURN_ON_PTHREAD_FAILURE(result); |
100 | 100 |
101 result = pthread_attr_destroy(&attr); | 101 result = pthread_attr_destroy(&attr); |
102 RETURN_ON_PTHREAD_FAILURE(result); | 102 RETURN_ON_PTHREAD_FAILURE(result); |
103 | 103 |
104 return 0; | 104 return 0; |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 ThreadLocalKey Thread::kUnsetThreadLocalKey = static_cast<pthread_key_t>(-1); | 108 ThreadLocalKey Thread::kUnsetThreadLocalKey = static_cast<pthread_key_t>(-1); |
109 | 109 ThreadId Thread::kInvalidThreadId = reinterpret_cast<ThreadId>(NULL); |
110 | 110 |
111 ThreadLocalKey Thread::CreateThreadLocal() { | 111 ThreadLocalKey Thread::CreateThreadLocal() { |
112 pthread_key_t key = kUnsetThreadLocalKey; | 112 pthread_key_t key = kUnsetThreadLocalKey; |
113 int result = pthread_key_create(&key, NULL); | 113 int result = pthread_key_create(&key, NULL); |
114 VALIDATE_PTHREAD_RESULT(result); | 114 VALIDATE_PTHREAD_RESULT(result); |
115 ASSERT(key != kUnsetThreadLocalKey); | 115 ASSERT(key != kUnsetThreadLocalKey); |
116 return key; | 116 return key; |
117 } | 117 } |
118 | 118 |
119 | 119 |
(...skipping 15 matching lines...) Expand all Loading... | |
135 const int kStackSize = (128 * kWordSize * KB); | 135 const int kStackSize = (128 * kWordSize * KB); |
136 return kStackSize; | 136 return kStackSize; |
137 } | 137 } |
138 | 138 |
139 | 139 |
140 ThreadId Thread::GetCurrentThreadId() { | 140 ThreadId Thread::GetCurrentThreadId() { |
141 return pthread_self(); | 141 return pthread_self(); |
142 } | 142 } |
143 | 143 |
144 | 144 |
145 intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { | |
siva
2013/12/11 02:52:21
Ditto.
Cutch
2013/12/11 17:44:56
Done.
| |
146 return reinterpret_cast<intptr_t>(id); | |
147 } | |
148 | |
149 | |
150 bool Thread::Compare(ThreadId a, ThreadId b) { | |
151 return pthread_equal(a, b) != 0; | |
152 } | |
153 | |
154 | |
145 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { | 155 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { |
146 ASSERT(thread_id == GetCurrentThreadId()); | 156 ASSERT(thread_id == GetCurrentThreadId()); |
147 ASSERT(cpu_usage != NULL); | 157 ASSERT(cpu_usage != NULL); |
148 // TODO(johnmccutchan): Enable this after fixing issue with macos directory | 158 // TODO(johnmccutchan): Enable this after fixing issue with macos directory |
149 // watcher. | 159 // watcher. |
150 const bool get_cpu_usage = false; | 160 const bool get_cpu_usage = false; |
151 if (get_cpu_usage) { | 161 if (get_cpu_usage) { |
152 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; | 162 mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT; |
153 thread_basic_info_data_t info_data; | 163 thread_basic_info_data_t info_data; |
154 thread_basic_info_t info = &info_data; | 164 thread_basic_info_t info = &info_data; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 | 316 |
307 void Monitor::NotifyAll() { | 317 void Monitor::NotifyAll() { |
308 // TODO(iposva): Do we need to track lock owners? | 318 // TODO(iposva): Do we need to track lock owners? |
309 int result = pthread_cond_broadcast(data_.cond()); | 319 int result = pthread_cond_broadcast(data_.cond()); |
310 VALIDATE_PTHREAD_RESULT(result); | 320 VALIDATE_PTHREAD_RESULT(result); |
311 } | 321 } |
312 | 322 |
313 } // namespace dart | 323 } // namespace dart |
314 | 324 |
315 #endif // defined(TARGET_OS_MACOS) | 325 #endif // defined(TARGET_OS_MACOS) |
OLD | NEW |