From c7e9e048edfa4cc247aa44052d4f0e919d6e87b2 Mon Sep 17 00:00:00 2001 From: "koda@google.com" Date: Thu, 15 Jan 2015 02:30:07 +0000 Subject: [PATCH] Rename Thread -> OSThread. It's a collection of static utility methods for primitive operations on OS threads. Make room in the namespace for upcoming class that will represent all the complex state of a VM thread. Review URL: https://codereview.chromium.org//796063006 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@42895 260f80e4-7a28-3924-810f-c04153c831b5 --- runtime/vm/code_observers.cc | 2 +- runtime/vm/dart_api_impl.cc | 8 +-- runtime/vm/dart_api_impl_test.cc | 2 +- runtime/vm/dart_api_state.h | 9 ++-- runtime/vm/debugger_api_impl_test.cc | 2 +- runtime/vm/elfgen.h | 2 +- runtime/vm/freelist.cc | 2 +- runtime/vm/freelist.h | 2 +- runtime/vm/isolate.cc | 18 +++---- runtime/vm/isolate.h | 4 +- runtime/vm/lockers.h | 2 +- runtime/vm/message_handler.h | 2 +- runtime/vm/message_handler_test.cc | 2 +- runtime/vm/native_symbol_win.cc | 2 +- runtime/vm/os_linux.cc | 2 +- runtime/vm/{thread.h => os_thread.h} | 18 ++++--- ...thread_android.cc => os_thread_android.cc} | 39 ++++++++------- .../{thread_android.h => os_thread_android.h} | 10 ++-- .../{thread_linux.cc => os_thread_linux.cc} | 39 ++++++++------- .../vm/{thread_macos.h => os_thread_linux.h} | 12 ++--- .../{thread_macos.cc => os_thread_macos.cc} | 39 ++++++++------- .../vm/{thread_linux.h => os_thread_macos.h} | 10 ++-- .../vm/{thread_win.cc => os_thread_win.cc} | 50 +++++++++---------- runtime/vm/{thread_win.h => os_thread_win.h} | 10 ++-- runtime/vm/os_win.cc | 6 +-- runtime/vm/pages.cc | 2 +- runtime/vm/port.cc | 2 +- runtime/vm/simulator_arm.cc | 4 +- runtime/vm/simulator_arm64.cc | 4 +- runtime/vm/simulator_mips.cc | 4 +- runtime/vm/thread_interrupter.cc | 40 ++++++++------- runtime/vm/thread_interrupter.h | 2 +- runtime/vm/thread_interrupter_android.cc | 2 +- runtime/vm/thread_interrupter_linux.cc | 2 +- runtime/vm/thread_interrupter_macos.cc | 2 +- runtime/vm/thread_interrupter_win.cc | 2 +- runtime/vm/thread_pool.cc | 2 +- runtime/vm/thread_pool.h | 2 +- runtime/vm/vm_sources.gypi | 18 +++---- 39 files changed, 195 insertions(+), 187 deletions(-) rename runtime/vm/{thread.h => os_thread.h} (88%) rename runtime/vm/{thread_android.cc => os_thread_android.cc} (88%) rename runtime/vm/{thread_android.h => os_thread_android.h} (87%) rename runtime/vm/{thread_linux.cc => os_thread_linux.cc} (88%) rename runtime/vm/{thread_macos.h => os_thread_linux.h} (85%) rename runtime/vm/{thread_macos.cc => os_thread_macos.cc} (89%) rename runtime/vm/{thread_linux.h => os_thread_macos.h} (87%) rename runtime/vm/{thread_win.cc => os_thread_win.cc} (89%) rename runtime/vm/{thread_win.h => os_thread_win.h} (93%) diff --git a/runtime/vm/code_observers.cc b/runtime/vm/code_observers.cc index dda3be28ca1..331a4be0963 100644 --- a/runtime/vm/code_observers.cc +++ b/runtime/vm/code_observers.cc @@ -6,7 +6,7 @@ #include "vm/code_observers.h" #include "vm/os.h" -#include "vm/thread.h" +#include "vm/os_thread.h" namespace dart { diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index ac26ef4b872..eda330aeada 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -47,7 +47,7 @@ DEFINE_FLAG(bool, check_function_fingerprints, false, DEFINE_FLAG(bool, trace_api, false, "Trace invocation of API calls (debug mode only)"); -ThreadLocalKey Api::api_native_key_ = Thread::kUnsetThreadLocalKey; +ThreadLocalKey Api::api_native_key_ = OSThread::kUnsetThreadLocalKey; Dart_Handle Api::true_handle_ = NULL; Dart_Handle Api::false_handle_ = NULL; Dart_Handle Api::null_handle_ = NULL; @@ -438,9 +438,9 @@ ApiLocalScope* Api::TopScope(Isolate* isolate) { void Api::InitOnce() { - ASSERT(api_native_key_ == Thread::kUnsetThreadLocalKey); - api_native_key_ = Thread::CreateThreadLocal(); - ASSERT(api_native_key_ != Thread::kUnsetThreadLocalKey); + ASSERT(api_native_key_ == OSThread::kUnsetThreadLocalKey); + api_native_key_ = OSThread::CreateThreadLocal(); + ASSERT(api_native_key_ != OSThread::kUnsetThreadLocalKey); } diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index 444e040002a..db3cb14aa70 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -7339,7 +7339,7 @@ TEST_CASE(IsolateInterrupt) { Isolate::SetInterruptCallback(IsolateInterruptTestCallback); sync = new Monitor(); - int result = Thread::Start(BusyLoop_start, 0); + int result = OSThread::Start(BusyLoop_start, 0); EXPECT_EQ(0, result); { diff --git a/runtime/vm/dart_api_state.h b/runtime/vm/dart_api_state.h index 7e5fa0a0ded..e9cf1835995 100644 --- a/runtime/vm/dart_api_state.h +++ b/runtime/vm/dart_api_state.h @@ -16,7 +16,7 @@ #include "vm/object.h" #include "vm/os.h" #include "vm/raw_object.h" -#include "vm/thread.h" +#include "vm/os_thread.h" #include "vm/visitor.h" #include "vm/handles_impl.h" @@ -617,17 +617,18 @@ class ApiNativeScope { ApiNativeScope() { // Currently no support for nesting native scopes. ASSERT(Current() == NULL); - Thread::SetThreadLocal(Api::api_native_key_, reinterpret_cast(this)); + OSThread::SetThreadLocal(Api::api_native_key_, + reinterpret_cast(this)); } ~ApiNativeScope() { ASSERT(Current() == this); - Thread::SetThreadLocal(Api::api_native_key_, 0); + OSThread::SetThreadLocal(Api::api_native_key_, 0); } static inline ApiNativeScope* Current() { return reinterpret_cast( - Thread::GetThreadLocal(Api::api_native_key_)); + OSThread::GetThreadLocal(Api::api_native_key_)); } Zone* zone() { return zone_.GetZone(); } diff --git a/runtime/vm/debugger_api_impl_test.cc b/runtime/vm/debugger_api_impl_test.cc index b01eed05db3..1ee1773c756 100644 --- a/runtime/vm/debugger_api_impl_test.cc +++ b/runtime/vm/debugger_api_impl_test.cc @@ -1504,7 +1504,7 @@ TEST_CASE(Debug_InterruptIsolate) { sync = new Monitor(); EXPECT(interrupt_isolate_id == ILLEGAL_ISOLATE_ID); Dart_SetPausedEventHandler(InterruptIsolateHandler); - int result = Thread::Start(InterruptIsolateRun, 0); + int result = OSThread::Start(InterruptIsolateRun, 0); EXPECT_EQ(0, result); // Wait for the test isolate to be created. diff --git a/runtime/vm/elfgen.h b/runtime/vm/elfgen.h index a17023b45de..f3fcd70cdc2 100644 --- a/runtime/vm/elfgen.h +++ b/runtime/vm/elfgen.h @@ -6,7 +6,7 @@ #define VM_ELFGEN_H_ #include "vm/lockers.h" -#include "vm/thread.h" +#include "vm/os_thread.h" namespace dart { diff --git a/runtime/vm/freelist.cc b/runtime/vm/freelist.cc index e82ce5d913d..00a4691d768 100644 --- a/runtime/vm/freelist.cc +++ b/runtime/vm/freelist.cc @@ -10,7 +10,7 @@ #include "vm/lockers.h" #include "vm/object.h" #include "vm/raw_object.h" -#include "vm/thread.h" +#include "vm/os_thread.h" namespace dart { diff --git a/runtime/vm/freelist.h b/runtime/vm/freelist.h index 910b81be9ab..38cad7f136a 100644 --- a/runtime/vm/freelist.h +++ b/runtime/vm/freelist.h @@ -9,7 +9,7 @@ #include "vm/allocation.h" #include "vm/bit_set.h" #include "vm/raw_object.h" -#include "vm/thread.h" +#include "vm/os_thread.h" namespace dart { diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc index b50fe61a2e1..ee450b62fa2 100644 --- a/runtime/vm/isolate.cc +++ b/runtime/vm/isolate.cc @@ -29,7 +29,7 @@ #include "vm/stub_code.h" #include "vm/symbols.h" #include "vm/tags.h" -#include "vm/thread.h" +#include "vm/os_thread.h" #include "vm/thread_interrupter.h" #include "vm/timer.h" #include "vm/visitor.h" @@ -580,7 +580,7 @@ void Isolate::SetCurrent(Isolate* current) { old_current->set_thread_state(NULL); Profiler::EndExecution(old_current); } - Thread::SetThreadLocal(isolate_key, reinterpret_cast(current)); + OSThread::SetThreadLocal(isolate_key, reinterpret_cast(current)); if (current != NULL) { ASSERT(current->thread_state() == NULL); InterruptableThreadState* thread_state = @@ -600,13 +600,13 @@ void Isolate::SetCurrent(Isolate* current) { // for a thread. Since an Isolate is the central repository for // storing all isolate specific information a single thread local key // is sufficient. -ThreadLocalKey Isolate::isolate_key = Thread::kUnsetThreadLocalKey; +ThreadLocalKey Isolate::isolate_key = OSThread::kUnsetThreadLocalKey; void Isolate::InitOnce() { - ASSERT(isolate_key == Thread::kUnsetThreadLocalKey); - isolate_key = Thread::CreateThreadLocal(); - ASSERT(isolate_key != Thread::kUnsetThreadLocalKey); + ASSERT(isolate_key == OSThread::kUnsetThreadLocalKey); + isolate_key = OSThread::CreateThreadLocal(); + ASSERT(isolate_key != OSThread::kUnsetThreadLocalKey); create_callback_ = NULL; isolates_list_monitor_ = new Monitor(); ASSERT(isolates_list_monitor_ != NULL); @@ -693,8 +693,8 @@ void Isolate::BuildName(const char* name_prefix) { // TODO(5411455): Use flag to override default value and Validate the // stack size by querying OS. uword Isolate::GetSpecifiedStackSize() { - ASSERT(Isolate::kStackSizeBuffer < Thread::GetMaxStackSize()); - uword stack_size = Thread::GetMaxStackSize() - Isolate::kStackSizeBuffer; + ASSERT(Isolate::kStackSizeBuffer < OSThread::GetMaxStackSize()); + uword stack_size = OSThread::GetMaxStackSize() - Isolate::kStackSizeBuffer; return stack_size; } @@ -1365,7 +1365,7 @@ intptr_t Isolate::ProfileInterrupt() { ProfileIdle(); return 1; } - ASSERT(state->id != Thread::kInvalidThreadId); + ASSERT(state->id != OSThread::kInvalidThreadId); ThreadInterrupter::InterruptThread(state); return 1; } diff --git a/runtime/vm/isolate.h b/runtime/vm/isolate.h index 05756f192e8..269ff6c5d97 100644 --- a/runtime/vm/isolate.h +++ b/runtime/vm/isolate.h @@ -16,7 +16,7 @@ #include "vm/random.h" #include "vm/store_buffer.h" #include "vm/tags.h" -#include "vm/thread.h" +#include "vm/os_thread.h" #include "vm/trace_buffer.h" #include "vm/timer.h" @@ -111,7 +111,7 @@ class Isolate : public BaseIsolate { ~Isolate(); static inline Isolate* Current() { - return reinterpret_cast(Thread::GetThreadLocal(isolate_key)); + return reinterpret_cast(OSThread::GetThreadLocal(isolate_key)); } static void SetCurrent(Isolate* isolate); diff --git a/runtime/vm/lockers.h b/runtime/vm/lockers.h index 3a4f0b2dc8b..f3f5540353b 100644 --- a/runtime/vm/lockers.h +++ b/runtime/vm/lockers.h @@ -9,7 +9,7 @@ #include "vm/allocation.h" #include "vm/globals.h" #include "vm/isolate.h" -#include "vm/thread.h" +#include "vm/os_thread.h" namespace dart { diff --git a/runtime/vm/message_handler.h b/runtime/vm/message_handler.h index 93d2923c83e..0e0837731c8 100644 --- a/runtime/vm/message_handler.h +++ b/runtime/vm/message_handler.h @@ -7,7 +7,7 @@ #include "vm/isolate.h" #include "vm/message.h" -#include "vm/thread.h" +#include "vm/os_thread.h" #include "vm/thread_pool.h" namespace dart { diff --git a/runtime/vm/message_handler_test.cc b/runtime/vm/message_handler_test.cc index ccd476fbc98..81325117bb0 100644 --- a/runtime/vm/message_handler_test.cc +++ b/runtime/vm/message_handler_test.cc @@ -311,7 +311,7 @@ UNIT_TEST_CASE(MessageHandler_Run) { info.handler = &handler; info.ports = ports; info.count = 10; - Thread::Start(SendMessages, reinterpret_cast(&info)); + OSThread::Start(SendMessages, reinterpret_cast(&info)); while (sleep < kMaxSleep && handler.message_count() < 11) { OS::Sleep(10); sleep += 10; diff --git a/runtime/vm/native_symbol_win.cc b/runtime/vm/native_symbol_win.cc index 459f376451b..09e511685e4 100644 --- a/runtime/vm/native_symbol_win.cc +++ b/runtime/vm/native_symbol_win.cc @@ -7,7 +7,7 @@ #include "vm/lockers.h" #include "vm/native_symbol.h" -#include "vm/thread.h" +#include "vm/os_thread.h" #include // NOLINT diff --git a/runtime/vm/os_linux.cc b/runtime/vm/os_linux.cc index 7a31892fe62..3d513ec7bc5 100644 --- a/runtime/vm/os_linux.cc +++ b/runtime/vm/os_linux.cc @@ -25,7 +25,7 @@ #include "vm/debuginfo.h" #include "vm/isolate.h" #include "vm/lockers.h" -#include "vm/thread.h" +#include "vm/os_thread.h" #include "vm/vtune.h" #include "vm/zone.h" diff --git a/runtime/vm/thread.h b/runtime/vm/os_thread.h similarity index 88% rename from runtime/vm/thread.h rename to runtime/vm/os_thread.h index 155312d7bab..457f06ebf7e 100644 --- a/runtime/vm/thread.h +++ b/runtime/vm/os_thread.h @@ -2,20 +2,21 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#ifndef VM_THREAD_H_ -#define VM_THREAD_H_ +#ifndef VM_OS_THREAD_H_ +#define VM_OS_THREAD_H_ #include "platform/globals.h" +#include "vm/allocation.h" // Declare the OS-specific types ahead of defining the generic classes. #if defined(TARGET_OS_ANDROID) -#include "vm/thread_android.h" +#include "vm/os_thread_android.h" #elif defined(TARGET_OS_LINUX) -#include "vm/thread_linux.h" +#include "vm/os_thread_linux.h" #elif defined(TARGET_OS_MACOS) -#include "vm/thread_macos.h" +#include "vm/os_thread_macos.h" #elif defined(TARGET_OS_WINDOWS) -#include "vm/thread_win.h" +#include "vm/os_thread_win.h" #else #error Unknown target os. #endif @@ -24,7 +25,8 @@ namespace dart { class Isolate; -class Thread { +// Low-level operations on OS platform threads. +class OSThread : AllStatic { public: static ThreadLocalKey kUnsetThreadLocalKey; static ThreadId kInvalidThreadId; @@ -107,4 +109,4 @@ class Monitor { } // namespace dart -#endif // VM_THREAD_H_ +#endif // VM_OS_THREAD_H_ diff --git a/runtime/vm/thread_android.cc b/runtime/vm/os_thread_android.cc similarity index 88% rename from runtime/vm/thread_android.cc rename to runtime/vm/os_thread_android.cc index 84571c888fc..f4b5233ad2b 100644 --- a/runtime/vm/thread_android.cc +++ b/runtime/vm/os_thread_android.cc @@ -2,10 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#include "platform/globals.h" +#include "platform/globals.h" // NOLINT #if defined(TARGET_OS_ANDROID) -#include "vm/thread.h" +#include "vm/os_thread.h" #include // NOLINT #include // NOLINT @@ -57,15 +57,15 @@ static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { class ThreadStartData { public: - ThreadStartData(Thread::ThreadStartFunction function, + ThreadStartData(OSThread::ThreadStartFunction function, uword parameter) : function_(function), parameter_(parameter) {} - Thread::ThreadStartFunction function() const { return function_; } + OSThread::ThreadStartFunction function() const { return function_; } uword parameter() const { return parameter_; } private: - Thread::ThreadStartFunction function_; + OSThread::ThreadStartFunction function_; uword parameter_; DISALLOW_COPY_AND_ASSIGN(ThreadStartData); @@ -78,7 +78,7 @@ class ThreadStartData { static void* ThreadStart(void* data_ptr) { ThreadStartData* data = reinterpret_cast(data_ptr); - Thread::ThreadStartFunction function = data->function(); + OSThread::ThreadStartFunction function = data->function(); uword parameter = data->parameter(); delete data; @@ -89,7 +89,7 @@ static void* ThreadStart(void* data_ptr) { } -int Thread::Start(ThreadStartFunction function, uword parameter) { +int OSThread::Start(ThreadStartFunction function, uword parameter) { pthread_attr_t attr; int result = pthread_attr_init(&attr); RETURN_ON_PTHREAD_FAILURE(result); @@ -97,7 +97,7 @@ int Thread::Start(ThreadStartFunction function, uword parameter) { result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); RETURN_ON_PTHREAD_FAILURE(result); - result = pthread_attr_setstacksize(&attr, Thread::GetMaxStackSize()); + result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); RETURN_ON_PTHREAD_FAILURE(result); ThreadStartData* data = new ThreadStartData(function, parameter); @@ -113,10 +113,11 @@ int Thread::Start(ThreadStartFunction function, uword parameter) { } -ThreadLocalKey Thread::kUnsetThreadLocalKey = static_cast(-1); -ThreadId Thread::kInvalidThreadId = static_cast(0); +ThreadLocalKey OSThread::kUnsetThreadLocalKey = + static_cast(-1); +ThreadId OSThread::kInvalidThreadId = static_cast(0); -ThreadLocalKey Thread::CreateThreadLocal() { +ThreadLocalKey OSThread::CreateThreadLocal() { pthread_key_t key = kUnsetThreadLocalKey; int result = pthread_key_create(&key, NULL); VALIDATE_PTHREAD_RESULT(result); @@ -125,48 +126,48 @@ ThreadLocalKey Thread::CreateThreadLocal() { } -void Thread::DeleteThreadLocal(ThreadLocalKey key) { +void OSThread::DeleteThreadLocal(ThreadLocalKey key) { ASSERT(key != kUnsetThreadLocalKey); int result = pthread_key_delete(key); VALIDATE_PTHREAD_RESULT(result); } -void Thread::SetThreadLocal(ThreadLocalKey key, uword value) { +void OSThread::SetThreadLocal(ThreadLocalKey key, uword value) { ASSERT(key != kUnsetThreadLocalKey); int result = pthread_setspecific(key, reinterpret_cast(value)); VALIDATE_PTHREAD_RESULT(result); } -intptr_t Thread::GetMaxStackSize() { +intptr_t OSThread::GetMaxStackSize() { const int kStackSize = (128 * kWordSize * KB); return kStackSize; } -ThreadId Thread::GetCurrentThreadId() { +ThreadId OSThread::GetCurrentThreadId() { return gettid(); } -bool Thread::Join(ThreadId id) { +bool OSThread::Join(ThreadId id) { return false; } -intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { +intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { ASSERT(sizeof(id) == sizeof(intptr_t)); return static_cast(id); } -bool Thread::Compare(ThreadId a, ThreadId b) { +bool OSThread::Compare(ThreadId a, ThreadId b) { return a == b; } -void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { +void OSThread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { ASSERT(thread_id == GetCurrentThreadId()); ASSERT(cpu_usage != NULL); struct timespec ts; diff --git a/runtime/vm/thread_android.h b/runtime/vm/os_thread_android.h similarity index 87% rename from runtime/vm/thread_android.h rename to runtime/vm/os_thread_android.h index 7cb6de56038..90a399704e4 100644 --- a/runtime/vm/thread_android.h +++ b/runtime/vm/os_thread_android.h @@ -2,11 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#ifndef VM_THREAD_ANDROID_H_ -#define VM_THREAD_ANDROID_H_ +#ifndef VM_OS_THREAD_ANDROID_H_ +#define VM_OS_THREAD_ANDROID_H_ -#if !defined(VM_THREAD_H_) -#error Do not include thread_android.h directly; use thread.h instead. +#if !defined(VM_OS_THREAD_H_) +#error Do not include os_thread_android.h directly; use os_thread.h instead. #endif #include @@ -72,4 +72,4 @@ class MonitorData { } // namespace dart -#endif // VM_THREAD_ANDROID_H_ +#endif // VM_OS_THREAD_ANDROID_H_ diff --git a/runtime/vm/thread_linux.cc b/runtime/vm/os_thread_linux.cc similarity index 88% rename from runtime/vm/thread_linux.cc rename to runtime/vm/os_thread_linux.cc index 10599fee420..a2b3cffee37 100644 --- a/runtime/vm/thread_linux.cc +++ b/runtime/vm/os_thread_linux.cc @@ -2,10 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#include "platform/globals.h" +#include "platform/globals.h" // NOLINT #if defined(TARGET_OS_LINUX) -#include "vm/thread.h" +#include "vm/os_thread.h" #include // NOLINT #include // NOLINT @@ -58,15 +58,15 @@ static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { class ThreadStartData { public: - ThreadStartData(Thread::ThreadStartFunction function, + ThreadStartData(OSThread::ThreadStartFunction function, uword parameter) : function_(function), parameter_(parameter) {} - Thread::ThreadStartFunction function() const { return function_; } + OSThread::ThreadStartFunction function() const { return function_; } uword parameter() const { return parameter_; } private: - Thread::ThreadStartFunction function_; + OSThread::ThreadStartFunction function_; uword parameter_; DISALLOW_COPY_AND_ASSIGN(ThreadStartData); @@ -79,7 +79,7 @@ class ThreadStartData { static void* ThreadStart(void* data_ptr) { ThreadStartData* data = reinterpret_cast(data_ptr); - Thread::ThreadStartFunction function = data->function(); + OSThread::ThreadStartFunction function = data->function(); uword parameter = data->parameter(); delete data; @@ -90,7 +90,7 @@ static void* ThreadStart(void* data_ptr) { } -int Thread::Start(ThreadStartFunction function, uword parameter) { +int OSThread::Start(ThreadStartFunction function, uword parameter) { pthread_attr_t attr; int result = pthread_attr_init(&attr); RETURN_ON_PTHREAD_FAILURE(result); @@ -98,7 +98,7 @@ int Thread::Start(ThreadStartFunction function, uword parameter) { result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); RETURN_ON_PTHREAD_FAILURE(result); - result = pthread_attr_setstacksize(&attr, Thread::GetMaxStackSize()); + result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); RETURN_ON_PTHREAD_FAILURE(result); ThreadStartData* data = new ThreadStartData(function, parameter); @@ -114,10 +114,11 @@ int Thread::Start(ThreadStartFunction function, uword parameter) { } -ThreadLocalKey Thread::kUnsetThreadLocalKey = static_cast(-1); -ThreadId Thread::kInvalidThreadId = static_cast(0); +ThreadLocalKey OSThread::kUnsetThreadLocalKey = + static_cast(-1); +ThreadId OSThread::kInvalidThreadId = static_cast(0); -ThreadLocalKey Thread::CreateThreadLocal() { +ThreadLocalKey OSThread::CreateThreadLocal() { pthread_key_t key = kUnsetThreadLocalKey; int result = pthread_key_create(&key, NULL); VALIDATE_PTHREAD_RESULT(result); @@ -126,48 +127,48 @@ ThreadLocalKey Thread::CreateThreadLocal() { } -void Thread::DeleteThreadLocal(ThreadLocalKey key) { +void OSThread::DeleteThreadLocal(ThreadLocalKey key) { ASSERT(key != kUnsetThreadLocalKey); int result = pthread_key_delete(key); VALIDATE_PTHREAD_RESULT(result); } -void Thread::SetThreadLocal(ThreadLocalKey key, uword value) { +void OSThread::SetThreadLocal(ThreadLocalKey key, uword value) { ASSERT(key != kUnsetThreadLocalKey); int result = pthread_setspecific(key, reinterpret_cast(value)); VALIDATE_PTHREAD_RESULT(result); } -intptr_t Thread::GetMaxStackSize() { +intptr_t OSThread::GetMaxStackSize() { const int kStackSize = (128 * kWordSize * KB); return kStackSize; } -ThreadId Thread::GetCurrentThreadId() { +ThreadId OSThread::GetCurrentThreadId() { return pthread_self(); } -bool Thread::Join(ThreadId id) { +bool OSThread::Join(ThreadId id) { return false; } -intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { +intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { ASSERT(sizeof(id) == sizeof(intptr_t)); return static_cast(id); } -bool Thread::Compare(ThreadId a, ThreadId b) { +bool OSThread::Compare(ThreadId a, ThreadId b) { return pthread_equal(a, b) != 0; } -void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { +void OSThread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { ASSERT(thread_id == GetCurrentThreadId()); ASSERT(cpu_usage != NULL); struct timespec ts; diff --git a/runtime/vm/thread_macos.h b/runtime/vm/os_thread_linux.h similarity index 85% rename from runtime/vm/thread_macos.h rename to runtime/vm/os_thread_linux.h index f4f9b1a20d4..840b36e9da1 100644 --- a/runtime/vm/thread_macos.h +++ b/runtime/vm/os_thread_linux.h @@ -2,11 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#ifndef VM_THREAD_MACOS_H_ -#define VM_THREAD_MACOS_H_ +#ifndef VM_OS_THREAD_LINUX_H_ +#define VM_OS_THREAD_LINUX_H_ -#if !defined(VM_THREAD_H_) -#error Do not include thread_macos.h directly; use thread.h instead. +#if !defined(VM_OS_THREAD_H_) +#error Do not include os_thread_linux.h directly; use os_thread.h instead. #endif #include @@ -30,7 +30,7 @@ class ThreadInlineImpl { return reinterpret_cast(pthread_getspecific(key)); } - friend class Thread; + friend class OSThread; DISALLOW_ALLOCATION(); DISALLOW_COPY_AND_ASSIGN(ThreadInlineImpl); @@ -72,4 +72,4 @@ class MonitorData { } // namespace dart -#endif // VM_THREAD_MACOS_H_ +#endif // VM_OS_THREAD_LINUX_H_ diff --git a/runtime/vm/thread_macos.cc b/runtime/vm/os_thread_macos.cc similarity index 89% rename from runtime/vm/thread_macos.cc rename to runtime/vm/os_thread_macos.cc index 6a0cf5d11d1..279425a7873 100644 --- a/runtime/vm/thread_macos.cc +++ b/runtime/vm/os_thread_macos.cc @@ -2,10 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#include "platform/globals.h" +#include "platform/globals.h" // NOLINT #if defined(TARGET_OS_MACOS) -#include "vm/thread.h" +#include "vm/os_thread.h" #include // NOLINT #include // NOLINT @@ -50,15 +50,15 @@ namespace dart { class ThreadStartData { public: - ThreadStartData(Thread::ThreadStartFunction function, + ThreadStartData(OSThread::ThreadStartFunction function, uword parameter) : function_(function), parameter_(parameter) {} - Thread::ThreadStartFunction function() const { return function_; } + OSThread::ThreadStartFunction function() const { return function_; } uword parameter() const { return parameter_; } private: - Thread::ThreadStartFunction function_; + OSThread::ThreadStartFunction function_; uword parameter_; DISALLOW_COPY_AND_ASSIGN(ThreadStartData); @@ -71,7 +71,7 @@ class ThreadStartData { static void* ThreadStart(void* data_ptr) { ThreadStartData* data = reinterpret_cast(data_ptr); - Thread::ThreadStartFunction function = data->function(); + OSThread::ThreadStartFunction function = data->function(); uword parameter = data->parameter(); delete data; @@ -82,7 +82,7 @@ static void* ThreadStart(void* data_ptr) { } -int Thread::Start(ThreadStartFunction function, uword parameter) { +int OSThread::Start(ThreadStartFunction function, uword parameter) { pthread_attr_t attr; int result = pthread_attr_init(&attr); RETURN_ON_PTHREAD_FAILURE(result); @@ -90,7 +90,7 @@ int Thread::Start(ThreadStartFunction function, uword parameter) { result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); RETURN_ON_PTHREAD_FAILURE(result); - result = pthread_attr_setstacksize(&attr, Thread::GetMaxStackSize()); + result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); RETURN_ON_PTHREAD_FAILURE(result); ThreadStartData* data = new ThreadStartData(function, parameter); @@ -106,10 +106,11 @@ int Thread::Start(ThreadStartFunction function, uword parameter) { } -ThreadLocalKey Thread::kUnsetThreadLocalKey = static_cast(-1); -ThreadId Thread::kInvalidThreadId = reinterpret_cast(NULL); +ThreadLocalKey OSThread::kUnsetThreadLocalKey = + static_cast(-1); +ThreadId OSThread::kInvalidThreadId = reinterpret_cast(NULL); -ThreadLocalKey Thread::CreateThreadLocal() { +ThreadLocalKey OSThread::CreateThreadLocal() { pthread_key_t key = kUnsetThreadLocalKey; int result = pthread_key_create(&key, NULL); VALIDATE_PTHREAD_RESULT(result); @@ -118,48 +119,48 @@ ThreadLocalKey Thread::CreateThreadLocal() { } -void Thread::DeleteThreadLocal(ThreadLocalKey key) { +void OSThread::DeleteThreadLocal(ThreadLocalKey key) { ASSERT(key != kUnsetThreadLocalKey); int result = pthread_key_delete(key); VALIDATE_PTHREAD_RESULT(result); } -void Thread::SetThreadLocal(ThreadLocalKey key, uword value) { +void OSThread::SetThreadLocal(ThreadLocalKey key, uword value) { ASSERT(key != kUnsetThreadLocalKey); int result = pthread_setspecific(key, reinterpret_cast(value)); VALIDATE_PTHREAD_RESULT(result); } -intptr_t Thread::GetMaxStackSize() { +intptr_t OSThread::GetMaxStackSize() { const int kStackSize = (128 * kWordSize * KB); return kStackSize; } -ThreadId Thread::GetCurrentThreadId() { +ThreadId OSThread::GetCurrentThreadId() { return pthread_self(); } -bool Thread::Join(ThreadId id) { +bool OSThread::Join(ThreadId id) { return false; } -intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { +intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { ASSERT(sizeof(id) == sizeof(intptr_t)); return reinterpret_cast(id); } -bool Thread::Compare(ThreadId a, ThreadId b) { +bool OSThread::Compare(ThreadId a, ThreadId b) { return pthread_equal(a, b) != 0; } -void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { +void OSThread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { ASSERT(thread_id == GetCurrentThreadId()); ASSERT(cpu_usage != NULL); // TODO(johnmccutchan): Enable this after fixing issue with macos directory diff --git a/runtime/vm/thread_linux.h b/runtime/vm/os_thread_macos.h similarity index 87% rename from runtime/vm/thread_linux.h rename to runtime/vm/os_thread_macos.h index 99878340638..b55eedca009 100644 --- a/runtime/vm/thread_linux.h +++ b/runtime/vm/os_thread_macos.h @@ -2,11 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#ifndef VM_THREAD_LINUX_H_ -#define VM_THREAD_LINUX_H_ +#ifndef VM_OS_THREAD_MACOS_H_ +#define VM_OS_THREAD_MACOS_H_ -#if !defined(VM_THREAD_H_) -#error Do not include thread_linux.h directly; use thread.h instead. +#if !defined(VM_OS_THREAD_H_) +#error Do not include os_thread_macos.h directly; use os_thread.h instead. #endif #include @@ -72,4 +72,4 @@ class MonitorData { } // namespace dart -#endif // VM_THREAD_LINUX_H_ +#endif // VM_OS_THREAD_MACOS_H_ diff --git a/runtime/vm/thread_win.cc b/runtime/vm/os_thread_win.cc similarity index 89% rename from runtime/vm/thread_win.cc rename to runtime/vm/os_thread_win.cc index 6ea61c2482a..e240b50092d 100644 --- a/runtime/vm/thread_win.cc +++ b/runtime/vm/os_thread_win.cc @@ -2,10 +2,10 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#include "platform/globals.h" +#include "platform/globals.h" // NOLINT #if defined(TARGET_OS_WINDOWS) -#include "vm/thread.h" +#include "vm/os_thread.h" #include // NOLINT @@ -16,14 +16,14 @@ namespace dart { class ThreadStartData { public: - ThreadStartData(Thread::ThreadStartFunction function, uword parameter) + ThreadStartData(OSThread::ThreadStartFunction function, uword parameter) : function_(function), parameter_(parameter) {} - Thread::ThreadStartFunction function() const { return function_; } + OSThread::ThreadStartFunction function() const { return function_; } uword parameter() const { return parameter_; } private: - Thread::ThreadStartFunction function_; + OSThread::ThreadStartFunction function_; uword parameter_; DISALLOW_COPY_AND_ASSIGN(ThreadStartData); @@ -36,7 +36,7 @@ class ThreadStartData { static unsigned int __stdcall ThreadEntry(void* data_ptr) { ThreadStartData* data = reinterpret_cast(data_ptr); - Thread::ThreadStartFunction function = data->function(); + OSThread::ThreadStartFunction function = data->function(); uword parameter = data->parameter(); delete data; @@ -52,10 +52,10 @@ static unsigned int __stdcall ThreadEntry(void* data_ptr) { } -int Thread::Start(ThreadStartFunction function, uword parameter) { +int OSThread::Start(ThreadStartFunction function, uword parameter) { ThreadStartData* start_data = new ThreadStartData(function, parameter); uint32_t tid; - uintptr_t thread = _beginthreadex(NULL, Thread::GetMaxStackSize(), + uintptr_t thread = _beginthreadex(NULL, OSThread::GetMaxStackSize(), ThreadEntry, start_data, 0, &tid); if (thread == -1L || thread == 0) { #ifdef DEBUG @@ -70,10 +70,10 @@ int Thread::Start(ThreadStartFunction function, uword parameter) { return 0; } -ThreadLocalKey Thread::kUnsetThreadLocalKey = TLS_OUT_OF_INDEXES; -ThreadId Thread::kInvalidThreadId = 0; +ThreadLocalKey OSThread::kUnsetThreadLocalKey = TLS_OUT_OF_INDEXES; +ThreadId OSThread::kInvalidThreadId = 0; -ThreadLocalKey Thread::CreateThreadLocal() { +ThreadLocalKey OSThread::CreateThreadLocal() { ThreadLocalKey key = TlsAlloc(); if (key == kUnsetThreadLocalKey) { FATAL1("TlsAlloc failed %d", GetLastError()); @@ -82,7 +82,7 @@ ThreadLocalKey Thread::CreateThreadLocal() { } -void Thread::DeleteThreadLocal(ThreadLocalKey key) { +void OSThread::DeleteThreadLocal(ThreadLocalKey key) { ASSERT(key != kUnsetThreadLocalKey); BOOL result = TlsFree(key); if (!result) { @@ -91,18 +91,18 @@ void Thread::DeleteThreadLocal(ThreadLocalKey key) { } -intptr_t Thread::GetMaxStackSize() { +intptr_t OSThread::GetMaxStackSize() { const int kStackSize = (128 * kWordSize * KB); return kStackSize; } -ThreadId Thread::GetCurrentThreadId() { +ThreadId OSThread::GetCurrentThreadId() { return ::GetCurrentThreadId(); } -bool Thread::Join(ThreadId id) { +bool OSThread::Join(ThreadId id) { HANDLE handle = OpenThread(SYNCHRONIZE, false, id); if (handle == INVALID_HANDLE_VALUE) { return false; @@ -113,18 +113,18 @@ bool Thread::Join(ThreadId id) { } -intptr_t Thread::ThreadIdToIntPtr(ThreadId id) { +intptr_t OSThread::ThreadIdToIntPtr(ThreadId id) { ASSERT(sizeof(id) <= sizeof(intptr_t)); return static_cast(id); } -bool Thread::Compare(ThreadId a, ThreadId b) { +bool OSThread::Compare(ThreadId a, ThreadId b) { return a == b; } -void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { +void OSThread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { static const int64_t kTimeEpoc = 116444736000000000LL; static const int64_t kTimeScaler = 10; // 100 ns to us. // Although win32 uses 64-bit integers for representing timestamps, @@ -156,7 +156,7 @@ void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) { } -void Thread::SetThreadLocal(ThreadLocalKey key, uword value) { +void OSThread::SetThreadLocal(ThreadLocalKey key, uword value) { ASSERT(key != kUnsetThreadLocalKey); BOOL result = TlsSetValue(key, reinterpret_cast(value)); if (!result) { @@ -231,7 +231,7 @@ void Mutex::Unlock() { ThreadLocalKey MonitorWaitData::monitor_wait_data_key_ = - Thread::kUnsetThreadLocalKey; + OSThread::kUnsetThreadLocalKey; Monitor::Monitor() { @@ -260,9 +260,9 @@ void Monitor::Exit() { void MonitorWaitData::ThreadExit() { if (MonitorWaitData::monitor_wait_data_key_ != - Thread::kUnsetThreadLocalKey) { + OSThread::kUnsetThreadLocalKey) { uword raw_wait_data = - Thread::GetThreadLocal(MonitorWaitData::monitor_wait_data_key_); + OSThread::GetThreadLocal(MonitorWaitData::monitor_wait_data_key_); if (raw_wait_data != 0) { MonitorWaitData* wait_data = reinterpret_cast(raw_wait_data); @@ -367,17 +367,17 @@ MonitorWaitData* MonitorData::GetMonitorWaitDataForThread() { // Ensure that the thread local key for monitor wait data objects is // initialized. ASSERT(MonitorWaitData::monitor_wait_data_key_ != - Thread::kUnsetThreadLocalKey); + OSThread::kUnsetThreadLocalKey); // Get the MonitorWaitData object containing the event for this // thread from thread local storage. Create it if it does not exist. uword raw_wait_data = - Thread::GetThreadLocal(MonitorWaitData::monitor_wait_data_key_); + OSThread::GetThreadLocal(MonitorWaitData::monitor_wait_data_key_); MonitorWaitData* wait_data = NULL; if (raw_wait_data == 0) { HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL); wait_data = new MonitorWaitData(event); - Thread::SetThreadLocal(MonitorWaitData::monitor_wait_data_key_, + OSThread::SetThreadLocal(MonitorWaitData::monitor_wait_data_key_, reinterpret_cast(wait_data)); } else { wait_data = reinterpret_cast(raw_wait_data); diff --git a/runtime/vm/thread_win.h b/runtime/vm/os_thread_win.h similarity index 93% rename from runtime/vm/thread_win.h rename to runtime/vm/os_thread_win.h index 49f620c1abd..664610156a3 100644 --- a/runtime/vm/thread_win.h +++ b/runtime/vm/os_thread_win.h @@ -2,11 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#ifndef VM_THREAD_WIN_H_ -#define VM_THREAD_WIN_H_ +#ifndef VM_OS_THREAD_WIN_H_ +#define VM_OS_THREAD_WIN_H_ -#if !defined(VM_THREAD_H_) -#error Do not include thread_win.h directly; use thread.h instead. +#if !defined(VM_OS_THREAD_H_) +#error Do not include os_thread_win.h directly; use os_thread.h instead. #endif #include "platform/assert.h" @@ -118,4 +118,4 @@ class MonitorData { } // namespace dart -#endif // VM_THREAD_WIN_H_ +#endif // VM_OS_THREAD_WIN_H_ diff --git a/runtime/vm/os_win.cc b/runtime/vm/os_win.cc index b0af73d0eaa..7c32ec6a258 100644 --- a/runtime/vm/os_win.cc +++ b/runtime/vm/os_win.cc @@ -13,7 +13,7 @@ #include "platform/utils.h" #include "platform/assert.h" -#include "vm/thread.h" +#include "vm/os_thread.h" #include "vm/vtune.h" namespace dart { @@ -247,7 +247,7 @@ int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { } va_list args_copy; va_copy(args_copy, args); - int written =_vsnprintf(str, size, format, args_copy); + int written = _vsnprintf(str, size, format, args_copy); va_end(args_copy); if (written < 0) { // _vsnprintf returns -1 if the number of characters to be written is @@ -315,7 +315,7 @@ void OS::InitOnce() { init_once_called = true; // Do not pop up a message box when abort is called. _set_abort_behavior(0, _WRITE_ABORT_MSG); - MonitorWaitData::monitor_wait_data_key_ = Thread::CreateThreadLocal(); + MonitorWaitData::monitor_wait_data_key_ = OSThread::CreateThreadLocal(); MonitorData::GetMonitorWaitDataForThread(); } diff --git a/runtime/vm/pages.cc b/runtime/vm/pages.cc index 08b74debaf2..ea6ec57845f 100644 --- a/runtime/vm/pages.cc +++ b/runtime/vm/pages.cc @@ -10,7 +10,7 @@ #include "vm/gc_sweeper.h" #include "vm/lockers.h" #include "vm/object.h" -#include "vm/thread.h" +#include "vm/os_thread.h" #include "vm/verified_memory.h" #include "vm/virtual_memory.h" diff --git a/runtime/vm/port.cc b/runtime/vm/port.cc index f39cba06f62..cfb9ac87d5d 100644 --- a/runtime/vm/port.cc +++ b/runtime/vm/port.cc @@ -9,7 +9,7 @@ #include "vm/isolate.h" #include "vm/lockers.h" #include "vm/message_handler.h" -#include "vm/thread.h" +#include "vm/os_thread.h" namespace dart { diff --git a/runtime/vm/simulator_arm.cc b/runtime/vm/simulator_arm.cc index 350e79e4753..0c926a871c9 100644 --- a/runtime/vm/simulator_arm.cc +++ b/runtime/vm/simulator_arm.cc @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#include +#include // NOLINT #include #include "vm/globals.h" @@ -20,7 +20,7 @@ #include "vm/lockers.h" #include "vm/native_arguments.h" #include "vm/stack_frame.h" -#include "vm/thread.h" +#include "vm/os_thread.h" namespace dart { diff --git a/runtime/vm/simulator_arm64.cc b/runtime/vm/simulator_arm64.cc index ca93c261bed..14a7fbb9aae 100644 --- a/runtime/vm/simulator_arm64.cc +++ b/runtime/vm/simulator_arm64.cc @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#include +#include // NOLINT #include #include "vm/globals.h" @@ -19,7 +19,7 @@ #include "vm/lockers.h" #include "vm/native_arguments.h" #include "vm/stack_frame.h" -#include "vm/thread.h" +#include "vm/os_thread.h" namespace dart { diff --git a/runtime/vm/simulator_mips.cc b/runtime/vm/simulator_mips.cc index 87ec3e33c52..0f1103823b0 100644 --- a/runtime/vm/simulator_mips.cc +++ b/runtime/vm/simulator_mips.cc @@ -2,7 +2,7 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#include +#include // NOLINT #include #include "vm/globals.h" @@ -19,7 +19,7 @@ #include "vm/lockers.h" #include "vm/native_arguments.h" #include "vm/stack_frame.h" -#include "vm/thread.h" +#include "vm/os_thread.h" namespace dart { diff --git a/runtime/vm/thread_interrupter.cc b/runtime/vm/thread_interrupter.cc index 0dd983b9ec9..b2f5f1c647d 100644 --- a/runtime/vm/thread_interrupter.cc +++ b/runtime/vm/thread_interrupter.cc @@ -51,19 +51,20 @@ DEFINE_FLAG(bool, trace_thread_interrupter, false, bool ThreadInterrupter::initialized_ = false; bool ThreadInterrupter::shutdown_ = false; bool ThreadInterrupter::thread_running_ = false; -ThreadId ThreadInterrupter::interrupter_thread_id_ = Thread::kInvalidThreadId; +ThreadId ThreadInterrupter::interrupter_thread_id_ = + OSThread::kInvalidThreadId; Monitor* ThreadInterrupter::monitor_ = NULL; intptr_t ThreadInterrupter::interrupt_period_ = 1000; intptr_t ThreadInterrupter::current_wait_time_ = Monitor::kNoTimeout; ThreadLocalKey ThreadInterrupter::thread_state_key_ = - Thread::kUnsetThreadLocalKey; + OSThread::kUnsetThreadLocalKey; void ThreadInterrupter::InitOnce() { ASSERT(!initialized_); - ASSERT(thread_state_key_ == Thread::kUnsetThreadLocalKey); - thread_state_key_ = Thread::CreateThreadLocal(); - ASSERT(thread_state_key_ != Thread::kUnsetThreadLocalKey); + ASSERT(thread_state_key_ == OSThread::kUnsetThreadLocalKey); + thread_state_key_ = OSThread::CreateThreadLocal(); + ASSERT(thread_state_key_ != OSThread::kUnsetThreadLocalKey); monitor_ = new Monitor(); ASSERT(monitor_ != NULL); initialized_ = true; @@ -75,15 +76,15 @@ void ThreadInterrupter::Startup() { if (FLAG_trace_thread_interrupter) { OS::Print("ThreadInterrupter starting up.\n"); } - ASSERT(interrupter_thread_id_ == Thread::kInvalidThreadId); + ASSERT(interrupter_thread_id_ == OSThread::kInvalidThreadId); { MonitorLocker startup_ml(monitor_); - Thread::Start(ThreadMain, 0); + OSThread::Start(ThreadMain, 0); while (!thread_running_) { startup_ml.Wait(); } } - ASSERT(interrupter_thread_id_ != Thread::kInvalidThreadId); + ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadId); if (FLAG_trace_thread_interrupter) { OS::Print("ThreadInterrupter running.\n"); } @@ -109,9 +110,9 @@ void ThreadInterrupter::Shutdown() { // On Windows, a thread's exit-code can leak into the process's exit-code, // if exiting 'at same time' as the process ends. By joining with the thread // here, we avoid this race condition. - ASSERT(interrupter_thread_id_ != Thread::kInvalidThreadId); - Thread::Join(interrupter_thread_id_); - interrupter_thread_id_ = Thread::kInvalidThreadId; + ASSERT(interrupter_thread_id_ != OSThread::kInvalidThreadId); + OSThread::Join(interrupter_thread_id_); + interrupter_thread_id_ = OSThread::kInvalidThreadId; #else // On non-Windows platforms, just wait for the thread interrupter to signal // that it has exited the loop. @@ -183,9 +184,9 @@ InterruptableThreadState* ThreadInterrupter::_EnsureThreadStateCreated() { InterruptableThreadState* state = CurrentThreadState(); if (state == NULL) { // Create thread state object lazily. - ThreadId current_thread = Thread::GetCurrentThreadId(); + ThreadId current_thread = OSThread::GetCurrentThreadId(); if (FLAG_trace_thread_interrupter) { - intptr_t tid = Thread::ThreadIdToIntPtr(current_thread); + intptr_t tid = OSThread::ThreadIdToIntPtr(current_thread); OS::Print("ThreadInterrupter Tracking %p\n", reinterpret_cast(tid)); } @@ -204,9 +205,9 @@ InterruptableThreadState* ThreadInterrupter::_EnsureThreadStateCreated() { void ThreadInterrupter::UpdateStateObject(ThreadInterruptCallback callback, void* data) { InterruptableThreadState* state = CurrentThreadState(); - ThreadId current_thread = Thread::GetCurrentThreadId(); + ThreadId current_thread = OSThread::GetCurrentThreadId(); ASSERT(state != NULL); - ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId())); + ASSERT(OSThread::Compare(state->id, OSThread::GetCurrentThreadId())); SetCurrentThreadState(NULL); // It is now safe to modify the state object. If an interrupt occurs, // the current thread state will be NULL. @@ -214,7 +215,7 @@ void ThreadInterrupter::UpdateStateObject(ThreadInterruptCallback callback, state->data = data; SetCurrentThreadState(state); if (FLAG_trace_thread_interrupter) { - intptr_t tid = Thread::ThreadIdToIntPtr(current_thread); + intptr_t tid = OSThread::ThreadIdToIntPtr(current_thread); if (callback == NULL) { OS::Print("ThreadInterrupter Cleared %p\n", reinterpret_cast(tid)); } else { @@ -231,13 +232,14 @@ InterruptableThreadState* ThreadInterrupter::GetCurrentThreadState() { InterruptableThreadState* ThreadInterrupter::CurrentThreadState() { InterruptableThreadState* state = reinterpret_cast( - Thread::GetThreadLocal(thread_state_key_)); + OSThread::GetThreadLocal(thread_state_key_)); return state; } void ThreadInterrupter::SetCurrentThreadState(InterruptableThreadState* state) { - Thread::SetThreadLocal(thread_state_key_, reinterpret_cast(state)); + OSThread::SetThreadLocal(thread_state_key_, + reinterpret_cast(state)); } @@ -279,7 +281,7 @@ void ThreadInterrupter::ThreadMain(uword parameters) { { // Signal to main thread we are ready. MonitorLocker startup_ml(monitor_); - interrupter_thread_id_ = Thread::GetCurrentThreadId(); + interrupter_thread_id_ = OSThread::GetCurrentThreadId(); thread_running_ = true; startup_ml.Notify(); } diff --git a/runtime/vm/thread_interrupter.h b/runtime/vm/thread_interrupter.h index 8731b9d9f53..5d0e1eff3ff 100644 --- a/runtime/vm/thread_interrupter.h +++ b/runtime/vm/thread_interrupter.h @@ -7,7 +7,7 @@ #include "vm/allocation.h" #include "vm/signal_handler.h" -#include "vm/thread.h" +#include "vm/os_thread.h" namespace dart { diff --git a/runtime/vm/thread_interrupter_android.cc b/runtime/vm/thread_interrupter_android.cc index 8fc8e3357d0..8784b31c561 100644 --- a/runtime/vm/thread_interrupter_android.cc +++ b/runtime/vm/thread_interrupter_android.cc @@ -29,7 +29,7 @@ class ThreadInterrupterAndroid : public AllStatic { // No interrupter state or callback. return; } - ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId())); + ASSERT(OSThread::Compare(state->id, OSThread::GetCurrentThreadId())); // Extract thread state. ucontext_t* context = reinterpret_cast(context_); mcontext_t mcontext = context->uc_mcontext; diff --git a/runtime/vm/thread_interrupter_linux.cc b/runtime/vm/thread_interrupter_linux.cc index b86b85e6dc7..b062f559efa 100644 --- a/runtime/vm/thread_interrupter_linux.cc +++ b/runtime/vm/thread_interrupter_linux.cc @@ -27,7 +27,7 @@ class ThreadInterrupterLinux : public AllStatic { // No interrupter state or callback. return; } - ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId())); + ASSERT(OSThread::Compare(state->id, OSThread::GetCurrentThreadId())); // Extract thread state. ucontext_t* context = reinterpret_cast(context_); mcontext_t mcontext = context->uc_mcontext; diff --git a/runtime/vm/thread_interrupter_macos.cc b/runtime/vm/thread_interrupter_macos.cc index 341f7c7d76b..d6a0fc94032 100644 --- a/runtime/vm/thread_interrupter_macos.cc +++ b/runtime/vm/thread_interrupter_macos.cc @@ -27,7 +27,7 @@ class ThreadInterrupterMacOS : public AllStatic { // No interrupter state or callback. return; } - ASSERT(Thread::Compare(state->id, Thread::GetCurrentThreadId())); + ASSERT(OSThread::Compare(state->id, OSThread::GetCurrentThreadId())); // Extract thread state. ucontext_t* context = reinterpret_cast(context_); mcontext_t mcontext = context->uc_mcontext; diff --git a/runtime/vm/thread_interrupter_win.cc b/runtime/vm/thread_interrupter_win.cc index 69e34814790..8f0ed959dde 100644 --- a/runtime/vm/thread_interrupter_win.cc +++ b/runtime/vm/thread_interrupter_win.cc @@ -52,7 +52,7 @@ class ThreadInterrupterWin : public AllStatic { static void Interrupt(InterruptableThreadState* state) { - ASSERT(!Thread::Compare(GetCurrentThreadId(), state->id)); + ASSERT(!OSThread::Compare(GetCurrentThreadId(), state->id)); HANDLE handle = OpenThread(THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION | THREAD_SUSPEND_RESUME, diff --git a/runtime/vm/thread_pool.cc b/runtime/vm/thread_pool.cc index 02c6e5a91ee..9e819b9d10b 100644 --- a/runtime/vm/thread_pool.cc +++ b/runtime/vm/thread_pool.cc @@ -231,7 +231,7 @@ void ThreadPool::Worker::StartThread() { ASSERT(task_ != NULL); } #endif - int result = Thread::Start(&Worker::Main, reinterpret_cast(this)); + int result = OSThread::Start(&Worker::Main, reinterpret_cast(this)); if (result != 0) { FATAL1("Could not start worker thread: result = %d.", result); } diff --git a/runtime/vm/thread_pool.h b/runtime/vm/thread_pool.h index d8475dc6e23..792aef7b238 100644 --- a/runtime/vm/thread_pool.h +++ b/runtime/vm/thread_pool.h @@ -6,7 +6,7 @@ #define VM_THREAD_POOL_H_ #include "vm/globals.h" -#include "vm/thread.h" +#include "vm/os_thread.h" namespace dart { diff --git a/runtime/vm/vm_sources.gypi b/runtime/vm/vm_sources.gypi index e869eb38261..3e1d5c45d8e 100644 --- a/runtime/vm/vm_sources.gypi +++ b/runtime/vm/vm_sources.gypi @@ -313,6 +313,15 @@ 'os_linux.cc', 'os_macos.cc', 'os_test.cc', + 'os_thread.h', + 'os_thread_android.cc', + 'os_thread_android.h', + 'os_thread_linux.cc', + 'os_thread_linux.h', + 'os_thread_macos.cc', + 'os_thread_macos.h', + 'os_thread_win.cc', + 'os_thread_win.h', 'os_win.cc', 'pages.cc', 'pages.h', @@ -413,11 +422,6 @@ 'symbols.h', 'tags.cc', 'tags.h', - 'thread.h', - 'thread_android.cc', - 'thread_android.h', - 'thread_linux.cc', - 'thread_linux.h', 'thread_interrupter.cc', 'thread_interrupter.h', 'thread_interrupter_android.cc', @@ -425,14 +429,10 @@ 'thread_interrupter_macos.cc', 'thread_interrupter_test.cc', 'thread_interrupter_win.cc', - 'thread_macos.cc', - 'thread_macos.h', 'thread_pool.cc', 'thread_pool.h', 'thread_pool_test.cc', 'thread_test.cc', - 'thread_win.cc', - 'thread_win.h', 'timer.cc', 'timer.h', 'token.cc',