Index: runtime/vm/os_thread_android.cc |
diff --git a/runtime/vm/os_thread_android.cc b/runtime/vm/os_thread_android.cc |
index f1c3a445838aef1bd2e4d965e87952340a2a63e4..d2205d15c811f3bddc3276b1b2b7c88743841ed6 100644 |
--- a/runtime/vm/os_thread_android.cc |
+++ b/runtime/vm/os_thread_android.cc |
@@ -64,14 +64,17 @@ static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) { |
class ThreadStartData { |
public: |
- ThreadStartData(OSThread::ThreadStartFunction function, |
+ ThreadStartData(const char* name, |
+ OSThread::ThreadStartFunction function, |
uword parameter) |
- : function_(function), parameter_(parameter) {} |
+ : name_(name), function_(function), parameter_(parameter) {} |
+ const char* name() const { return name_; } |
OSThread::ThreadStartFunction function() const { return function_; } |
uword parameter() const { return parameter_; } |
private: |
+ const char* name_; |
OSThread::ThreadStartFunction function_; |
uword parameter_; |
@@ -85,10 +88,16 @@ class ThreadStartData { |
static void* ThreadStart(void* data_ptr) { |
ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr); |
+ const char* name = data->name(); |
OSThread::ThreadStartFunction function = data->function(); |
uword parameter = data->parameter(); |
delete data; |
+ // Create new OSThread object and set as TLS for new thread. |
+ OSThread* thread = new OSThread(); |
+ OSThread::SetCurrent(thread); |
+ thread->set_name(name); |
+ |
// Call the supplied thread start function handing it its parameters. |
function(parameter); |
@@ -96,7 +105,9 @@ static void* ThreadStart(void* data_ptr) { |
} |
-int OSThread::Start(ThreadStartFunction function, uword parameter) { |
+int OSThread::Start(const char* name, |
+ ThreadStartFunction function, |
+ uword parameter) { |
pthread_attr_t attr; |
int result = pthread_attr_init(&attr); |
RETURN_ON_PTHREAD_FAILURE(result); |
@@ -104,7 +115,7 @@ int OSThread::Start(ThreadStartFunction function, uword parameter) { |
result = pthread_attr_setstacksize(&attr, OSThread::GetMaxStackSize()); |
RETURN_ON_PTHREAD_FAILURE(result); |
- ThreadStartData* data = new ThreadStartData(function, parameter); |
+ ThreadStartData* data = new ThreadStartData(name, function, parameter); |
pthread_t tid; |
result = pthread_create(&tid, &attr, ThreadStart, data); |