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