Index: runtime/vm/os_thread_linux.cc |
diff --git a/runtime/vm/os_thread_linux.cc b/runtime/vm/os_thread_linux.cc |
index f48b6b015ea59c36c2f334aed091bb0e3893a454..470c3e348a265d3aa3ba965d6b6f17c884d1c9e7 100644 |
--- a/runtime/vm/os_thread_linux.cc |
+++ b/runtime/vm/os_thread_linux.cc |
@@ -78,14 +78,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_; |
@@ -99,10 +102,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); |
@@ -110,7 +119,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); |
@@ -118,7 +129,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); |