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 #ifndef RUNTIME_VM_OS_THREAD_H_ | 5 #ifndef RUNTIME_VM_OS_THREAD_H_ |
6 #define RUNTIME_VM_OS_THREAD_H_ | 6 #define RUNTIME_VM_OS_THREAD_H_ |
7 | 7 |
8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 } | 109 } |
110 | 110 |
111 static bool GetCurrentStackBounds(uword* lower, uword* upper); | 111 static bool GetCurrentStackBounds(uword* lower, uword* upper); |
112 | 112 |
113 // Used to temporarily disable or enable thread interrupts. | 113 // Used to temporarily disable or enable thread interrupts. |
114 void DisableThreadInterrupts(); | 114 void DisableThreadInterrupts(); |
115 void EnableThreadInterrupts(); | 115 void EnableThreadInterrupts(); |
116 bool ThreadInterruptsEnabled(); | 116 bool ThreadInterruptsEnabled(); |
117 | 117 |
118 // The currently executing thread, or NULL if not yet initialized. | 118 // The currently executing thread, or NULL if not yet initialized. |
119 static OSThread* TryCurrent() { | 119 static OSThread* Current() { |
120 BaseThread* thread = GetCurrentTLS(); | 120 BaseThread* thread = GetCurrentTLS(); |
121 OSThread* os_thread = NULL; | 121 OSThread* os_thread = NULL; |
122 if (thread != NULL) { | 122 if (thread != NULL) { |
123 if (thread->is_os_thread()) { | 123 if (thread->is_os_thread()) { |
124 os_thread = reinterpret_cast<OSThread*>(thread); | 124 os_thread = reinterpret_cast<OSThread*>(thread); |
125 } else { | 125 } else { |
126 Thread* vm_thread = reinterpret_cast<Thread*>(thread); | 126 Thread* vm_thread = reinterpret_cast<Thread*>(thread); |
127 os_thread = GetOSThreadFromThread(vm_thread); | 127 os_thread = GetOSThreadFromThread(vm_thread); |
128 } | 128 } |
129 } | 129 } else { |
130 return os_thread; | |
131 } | |
132 | |
133 // The currently executing thread. If there is no currently executing thread, | |
134 // a new OSThread is created and returned. | |
135 static OSThread* Current() { | |
136 OSThread* os_thread = TryCurrent(); | |
137 if (os_thread == NULL) { | |
138 os_thread = CreateAndSetUnknownThread(); | 130 os_thread = CreateAndSetUnknownThread(); |
139 } | 131 } |
140 return os_thread; | 132 return os_thread; |
141 } | 133 } |
142 static void SetCurrent(OSThread* current); | 134 static void SetCurrent(OSThread* current); |
143 | 135 |
144 // TODO(5411455): Use flag to override default value and Validate the | 136 // TODO(5411455): Use flag to override default value and Validate the |
145 // stack size by querying OS. | 137 // stack size by querying OS. |
146 static uword GetSpecifiedStackSize() { | 138 static uword GetSpecifiedStackSize() { |
147 ASSERT(OSThread::kStackSizeBuffer < OSThread::GetMaxStackSize()); | 139 ASSERT(OSThread::kStackSizeBuffer < OSThread::GetMaxStackSize()); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 friend class SafepointMonitorLocker; | 344 friend class SafepointMonitorLocker; |
353 friend void Dart_TestMonitor(); | 345 friend void Dart_TestMonitor(); |
354 DISALLOW_COPY_AND_ASSIGN(Monitor); | 346 DISALLOW_COPY_AND_ASSIGN(Monitor); |
355 }; | 347 }; |
356 | 348 |
357 | 349 |
358 } // namespace dart | 350 } // namespace dart |
359 | 351 |
360 | 352 |
361 #endif // RUNTIME_VM_OS_THREAD_H_ | 353 #endif // RUNTIME_VM_OS_THREAD_H_ |
OLD | NEW |