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_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include "platform/thread.h" | 8 #include "platform/thread.h" |
9 | 9 |
10 #include <process.h> // NOLINT | 10 #include <process.h> // NOLINT |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 void ThreadInlineImpl::DestroyThreadId(ThreadId thread_id) { | 92 void ThreadInlineImpl::DestroyThreadId(ThreadId thread_id) { |
93 ASSERT(thread_id != NULL); | 93 ASSERT(thread_id != NULL); |
94 // Destroy thread ID. | 94 // Destroy thread ID. |
95 CloseHandle(thread_id); | 95 CloseHandle(thread_id); |
96 } | 96 } |
97 | 97 |
98 | 98 |
99 ThreadLocalKey ThreadInlineImpl::thread_id_key = Thread::kUnsetThreadLocalKey; | 99 ThreadLocalKey ThreadInlineImpl::thread_id_key = Thread::kUnsetThreadLocalKey; |
100 | 100 |
101 ThreadLocalKey Thread::kUnsetThreadLocalKey = TLS_OUT_OF_INDEXES; | 101 ThreadLocalKey Thread::kUnsetThreadLocalKey = TLS_OUT_OF_INDEXES; |
102 | 102 ThreadId Thread::kInvalidThreadId = |
| 103 reinterpret_cast<ThreadId>(INVALID_HANDLE_VALUE); |
103 | 104 |
104 ThreadLocalKey Thread::CreateThreadLocal() { | 105 ThreadLocalKey Thread::CreateThreadLocal() { |
105 ThreadLocalKey key = TlsAlloc(); | 106 ThreadLocalKey key = TlsAlloc(); |
106 if (key == kUnsetThreadLocalKey) { | 107 if (key == kUnsetThreadLocalKey) { |
107 FATAL1("TlsAlloc failed %d", GetLastError()); | 108 FATAL1("TlsAlloc failed %d", GetLastError()); |
108 } | 109 } |
109 return key; | 110 return key; |
110 } | 111 } |
111 | 112 |
112 | 113 |
(...skipping 13 matching lines...) Expand all Loading... |
126 | 127 |
127 | 128 |
128 ThreadId Thread::GetCurrentThreadId() { | 129 ThreadId Thread::GetCurrentThreadId() { |
129 ThreadId id = reinterpret_cast<ThreadId>( | 130 ThreadId id = reinterpret_cast<ThreadId>( |
130 Thread::GetThreadLocal(ThreadInlineImpl::thread_id_key)); | 131 Thread::GetThreadLocal(ThreadInlineImpl::thread_id_key)); |
131 ASSERT(id != NULL); | 132 ASSERT(id != NULL); |
132 return id; | 133 return id; |
133 } | 134 } |
134 | 135 |
135 | 136 |
| 137 intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { |
| 138 ASSERT(sizeof(id) == sizeof(intptr_t)); |
| 139 return reinterpret_cast<intptr_t>(id); |
| 140 } |
| 141 |
| 142 |
| 143 bool Thread::Compare(ThreadId a, ThreadId b) { |
| 144 return a == b; |
| 145 } |
| 146 |
| 147 |
136 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { | 148 void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { |
137 static const int64_t kTimeEpoc = 116444736000000000LL; | 149 static const int64_t kTimeEpoc = 116444736000000000LL; |
138 static const int64_t kTimeScaler = 10; // 100 ns to us. | 150 static const int64_t kTimeScaler = 10; // 100 ns to us. |
139 // Although win32 uses 64-bit integers for representing timestamps, | 151 // Although win32 uses 64-bit integers for representing timestamps, |
140 // these are packed into a FILETIME structure. The FILETIME | 152 // these are packed into a FILETIME structure. The FILETIME |
141 // structure is just a struct representing a 64-bit integer. The | 153 // structure is just a struct representing a 64-bit integer. The |
142 // TimeStamp union allows access to both a FILETIME and an integer | 154 // TimeStamp union allows access to both a FILETIME and an integer |
143 // representation of the timestamp. The Windows timestamp is in | 155 // representation of the timestamp. The Windows timestamp is in |
144 // 100-nanosecond intervals since January 1, 1601. | 156 // 100-nanosecond intervals since January 1, 1601. |
145 union TimeStamp { | 157 union TimeStamp { |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 // timeout before we signal it, that object will get an extra | 450 // timeout before we signal it, that object will get an extra |
439 // signal. This will be treated as a spurious wake-up and is OK | 451 // signal. This will be treated as a spurious wake-up and is OK |
440 // since all uses of monitors should recheck the condition after a | 452 // since all uses of monitors should recheck the condition after a |
441 // Wait. | 453 // Wait. |
442 data_.SignalAndRemoveAllWaiters(); | 454 data_.SignalAndRemoveAllWaiters(); |
443 } | 455 } |
444 | 456 |
445 } // namespace dart | 457 } // namespace dart |
446 | 458 |
447 #endif // defined(TARGET_OS_WINDOWS) | 459 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |