mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
[standalone] Name dart:io threads, take 2.
Mac's pthread_setname_np assumes the current thread. Bug: US-588 Change-Id: Ibbddd1f7bffeab10fd470a6176f68b1c0440aa99 Reviewed-on: https://dart-review.googlesource.com/c/93120 Reviewed-by: Zach Anderson <zra@google.com> Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
parent
7a63d31151
commit
0f24b9e7ae
|
@ -401,8 +401,9 @@ void EventHandlerImplementation::Poll(uword args) {
|
|||
}
|
||||
|
||||
void EventHandlerImplementation::Start(EventHandler* handler) {
|
||||
int result = Thread::Start(&EventHandlerImplementation::Poll,
|
||||
reinterpret_cast<uword>(handler));
|
||||
int result =
|
||||
Thread::Start("dart:io EventHandler", &EventHandlerImplementation::Poll,
|
||||
reinterpret_cast<uword>(handler));
|
||||
if (result != 0) {
|
||||
FATAL1("Failed to start event handler thread %d", result);
|
||||
}
|
||||
|
|
|
@ -553,8 +553,9 @@ void EventHandlerImplementation::Poll(uword args) {
|
|||
}
|
||||
|
||||
void EventHandlerImplementation::Start(EventHandler* handler) {
|
||||
int result = Thread::Start(&EventHandlerImplementation::Poll,
|
||||
reinterpret_cast<uword>(handler));
|
||||
int result =
|
||||
Thread::Start("dart:io EventHandler", &EventHandlerImplementation::Poll,
|
||||
reinterpret_cast<uword>(handler));
|
||||
if (result != 0) {
|
||||
FATAL1("Failed to start event handler thread %d", result);
|
||||
}
|
||||
|
|
|
@ -405,8 +405,9 @@ void EventHandlerImplementation::Poll(uword args) {
|
|||
}
|
||||
|
||||
void EventHandlerImplementation::Start(EventHandler* handler) {
|
||||
int result = Thread::Start(&EventHandlerImplementation::Poll,
|
||||
reinterpret_cast<uword>(handler));
|
||||
int result =
|
||||
Thread::Start("dart:io EventHandler", &EventHandlerImplementation::Poll,
|
||||
reinterpret_cast<uword>(handler));
|
||||
if (result != 0) {
|
||||
FATAL1("Failed to start event handler thread %d", result);
|
||||
}
|
||||
|
|
|
@ -464,7 +464,8 @@ void EventHandlerImplementation::EventHandlerEntry(uword args) {
|
|||
}
|
||||
|
||||
void EventHandlerImplementation::Start(EventHandler* handler) {
|
||||
int result = Thread::Start(&EventHandlerImplementation::EventHandlerEntry,
|
||||
int result = Thread::Start("dart:io EventHandler",
|
||||
&EventHandlerImplementation::EventHandlerEntry,
|
||||
reinterpret_cast<uword>(handler));
|
||||
if (result != 0) {
|
||||
FATAL1("Failed to start event handler thread %d", result);
|
||||
|
|
|
@ -301,7 +301,8 @@ bool Handle::IssueRead() {
|
|||
// Completing asynchronously through thread.
|
||||
pending_read_ = buffer;
|
||||
read_thread_starting_ = true;
|
||||
int result = Thread::Start(ReadFileThread, reinterpret_cast<uword>(this));
|
||||
int result = Thread::Start("dart:io ReadFile", ReadFileThread,
|
||||
reinterpret_cast<uword>(this));
|
||||
if (result != 0) {
|
||||
FATAL1("Failed to start read file thread %d", result);
|
||||
}
|
||||
|
@ -781,7 +782,8 @@ intptr_t StdHandle::Write(const void* buffer, intptr_t num_bytes) {
|
|||
// the events it puts on the IO completion port. The reference is
|
||||
// Released by DeleteIfClosed.
|
||||
Retain();
|
||||
int result = Thread::Start(WriteFileThread, reinterpret_cast<uword>(this));
|
||||
int result = Thread::Start("dart:io WriteFile", WriteFileThread,
|
||||
reinterpret_cast<uword>(this));
|
||||
if (result != 0) {
|
||||
FATAL1("Failed to start write file thread %d", result);
|
||||
}
|
||||
|
@ -1460,8 +1462,8 @@ void EventHandlerImplementation::EventHandlerEntry(uword args) {
|
|||
}
|
||||
|
||||
void EventHandlerImplementation::Start(EventHandler* handler) {
|
||||
int result =
|
||||
Thread::Start(EventHandlerEntry, reinterpret_cast<uword>(handler));
|
||||
int result = Thread::Start("dart:io EventHandler", EventHandlerEntry,
|
||||
reinterpret_cast<uword>(handler));
|
||||
if (result != 0) {
|
||||
FATAL1("Failed to start event handler thread %d", result);
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ class FSEventsWatcher {
|
|||
FSEventsWatcher() : run_loop_(0) { Start(); }
|
||||
|
||||
void Start() {
|
||||
Thread::Start(Run, reinterpret_cast<uword>(this));
|
||||
Thread::Start("dart:io FileWatcher", Run, reinterpret_cast<uword>(this));
|
||||
monitor_.Enter();
|
||||
while (run_loop_ == NULL) {
|
||||
monitor_.Wait(Monitor::kNoTimeout);
|
||||
|
|
|
@ -141,7 +141,8 @@ class ExitCodeHandler {
|
|||
}
|
||||
|
||||
// Start thread that handles process exits when wait returns.
|
||||
int result = Thread::Start(ExitCodeHandlerEntry, 0);
|
||||
int result =
|
||||
Thread::Start("dart:io Process.start", ExitCodeHandlerEntry, 0);
|
||||
if (result != 0) {
|
||||
FATAL1("Failed to start exit code handler worker thread %d", result);
|
||||
}
|
||||
|
|
|
@ -167,7 +167,8 @@ class ExitCodeHandler {
|
|||
}
|
||||
|
||||
// Start thread that handles process exits when wait returns.
|
||||
intptr_t result = Thread::Start(ExitCodeHandlerEntry, 0);
|
||||
intptr_t result =
|
||||
Thread::Start("dart:io Process.start", ExitCodeHandlerEntry, 0);
|
||||
if (result != 0) {
|
||||
FATAL1("Failed to start exit code handler worker thread %ld", result);
|
||||
}
|
||||
|
|
|
@ -141,7 +141,8 @@ class ExitCodeHandler {
|
|||
}
|
||||
|
||||
// Start thread that handles process exits when wait returns.
|
||||
int result = Thread::Start(ExitCodeHandlerEntry, 0);
|
||||
int result =
|
||||
Thread::Start("dart:io Process.start", ExitCodeHandlerEntry, 0);
|
||||
if (result != 0) {
|
||||
FATAL1("Failed to start exit code handler worker thread %d", result);
|
||||
}
|
||||
|
|
|
@ -140,7 +140,8 @@ class ExitCodeHandler {
|
|||
}
|
||||
|
||||
// Start thread that handles process exits when wait returns.
|
||||
int result = Thread::Start(ExitCodeHandlerEntry, 0);
|
||||
int result =
|
||||
Thread::Start("dart:io Process.start", ExitCodeHandlerEntry, 0);
|
||||
if (result != 0) {
|
||||
FATAL1("Failed to start exit code handler worker thread %d", result);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,9 @@ class Thread {
|
|||
// Start a thread running the specified function. Returns 0 if the
|
||||
// thread started successfuly and a system specific error code if
|
||||
// the thread failed to start.
|
||||
static int Start(ThreadStartFunction function, uword parameters);
|
||||
static int Start(const char* name,
|
||||
ThreadStartFunction function,
|
||||
uword parameters);
|
||||
|
||||
static ThreadLocalKey CreateThreadLocal();
|
||||
static void DeleteThreadLocal(ThreadLocalKey key);
|
||||
|
|
|
@ -58,13 +58,17 @@ static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) {
|
|||
|
||||
class ThreadStartData {
|
||||
public:
|
||||
ThreadStartData(Thread::ThreadStartFunction function, uword parameter)
|
||||
: function_(function), parameter_(parameter) {}
|
||||
ThreadStartData(const char* name,
|
||||
Thread::ThreadStartFunction function,
|
||||
uword parameter)
|
||||
: name_(name), function_(function), parameter_(parameter) {}
|
||||
|
||||
const char* name() const { return name_; }
|
||||
Thread::ThreadStartFunction function() const { return function_; }
|
||||
uword parameter() const { return parameter_; }
|
||||
|
||||
private:
|
||||
const char* name_;
|
||||
Thread::ThreadStartFunction function_;
|
||||
uword parameter_;
|
||||
|
||||
|
@ -77,17 +81,23 @@ class ThreadStartData {
|
|||
static void* ThreadStart(void* data_ptr) {
|
||||
ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr);
|
||||
|
||||
const char* name = data->name();
|
||||
Thread::ThreadStartFunction function = data->function();
|
||||
uword parameter = data->parameter();
|
||||
delete data;
|
||||
|
||||
// Set the thread name.
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
|
||||
// Call the supplied thread start function handing it its parameters.
|
||||
function(parameter);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int Thread::Start(ThreadStartFunction function, uword parameter) {
|
||||
int Thread::Start(const char* name,
|
||||
ThreadStartFunction function,
|
||||
uword parameter) {
|
||||
pthread_attr_t attr;
|
||||
int result = pthread_attr_init(&attr);
|
||||
RETURN_ON_PTHREAD_FAILURE(result);
|
||||
|
@ -98,7 +108,7 @@ int Thread::Start(ThreadStartFunction function, uword parameter) {
|
|||
result = pthread_attr_setstacksize(&attr, Thread::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);
|
||||
|
|
|
@ -8,8 +8,12 @@
|
|||
#include "bin/thread.h"
|
||||
#include "bin/thread_fuchsia.h"
|
||||
|
||||
#include <errno.h> // NOLINT
|
||||
#include <sys/time.h> // NOLINT
|
||||
#include <errno.h> // NOLINT
|
||||
#include <sys/time.h> // NOLINT
|
||||
#include <zircon/status.h>
|
||||
#include <zircon/syscalls.h>
|
||||
#include <zircon/threads.h>
|
||||
#include <zircon/types.h>
|
||||
|
||||
#include "platform/assert.h"
|
||||
#include "platform/utils.h"
|
||||
|
@ -57,13 +61,17 @@ static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) {
|
|||
|
||||
class ThreadStartData {
|
||||
public:
|
||||
ThreadStartData(Thread::ThreadStartFunction function, uword parameter)
|
||||
: function_(function), parameter_(parameter) {}
|
||||
ThreadStartData(const char* name,
|
||||
Thread::ThreadStartFunction function,
|
||||
uword parameter)
|
||||
: name_(name), function_(function), parameter_(parameter) {}
|
||||
|
||||
const char* name() const { return name_; }
|
||||
Thread::ThreadStartFunction function() const { return function_; }
|
||||
uword parameter() const { return parameter_; }
|
||||
|
||||
private:
|
||||
const char* name_;
|
||||
Thread::ThreadStartFunction function_;
|
||||
uword parameter_;
|
||||
|
||||
|
@ -76,17 +84,24 @@ class ThreadStartData {
|
|||
static void* ThreadStart(void* data_ptr) {
|
||||
ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr);
|
||||
|
||||
const char* name = data->name();
|
||||
Thread::ThreadStartFunction function = data->function();
|
||||
uword parameter = data->parameter();
|
||||
delete data;
|
||||
|
||||
// Set the thread name.
|
||||
zx_handle_t thread_handle = thrd_get_zx_handle(thrd_current());
|
||||
zx_object_set_property(thread_handle, ZX_PROP_NAME, name, strlen(name) + 1);
|
||||
|
||||
// Call the supplied thread start function handing it its parameters.
|
||||
function(parameter);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int Thread::Start(ThreadStartFunction function, uword parameter) {
|
||||
int Thread::Start(const char* name,
|
||||
ThreadStartFunction function,
|
||||
uword parameter) {
|
||||
pthread_attr_t attr;
|
||||
int result = pthread_attr_init(&attr);
|
||||
RETURN_ON_PTHREAD_FAILURE(result);
|
||||
|
@ -97,7 +112,7 @@ int Thread::Start(ThreadStartFunction function, uword parameter) {
|
|||
result = pthread_attr_setstacksize(&attr, Thread::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);
|
||||
|
|
|
@ -58,13 +58,17 @@ static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) {
|
|||
|
||||
class ThreadStartData {
|
||||
public:
|
||||
ThreadStartData(Thread::ThreadStartFunction function, uword parameter)
|
||||
: function_(function), parameter_(parameter) {}
|
||||
ThreadStartData(const char* name,
|
||||
Thread::ThreadStartFunction function,
|
||||
uword parameter)
|
||||
: name_(name), function_(function), parameter_(parameter) {}
|
||||
|
||||
const char* name() const { return name_; }
|
||||
Thread::ThreadStartFunction function() const { return function_; }
|
||||
uword parameter() const { return parameter_; }
|
||||
|
||||
private:
|
||||
const char* name_;
|
||||
Thread::ThreadStartFunction function_;
|
||||
uword parameter_;
|
||||
|
||||
|
@ -77,17 +81,23 @@ class ThreadStartData {
|
|||
static void* ThreadStart(void* data_ptr) {
|
||||
ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr);
|
||||
|
||||
const char* name = data->name();
|
||||
Thread::ThreadStartFunction function = data->function();
|
||||
uword parameter = data->parameter();
|
||||
delete data;
|
||||
|
||||
// Set the thread name.
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
|
||||
// Call the supplied thread start function handing it its parameters.
|
||||
function(parameter);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int Thread::Start(ThreadStartFunction function, uword parameter) {
|
||||
int Thread::Start(const char* name,
|
||||
ThreadStartFunction function,
|
||||
uword parameter) {
|
||||
pthread_attr_t attr;
|
||||
int result = pthread_attr_init(&attr);
|
||||
RETURN_ON_PTHREAD_FAILURE(result);
|
||||
|
@ -98,7 +108,7 @@ int Thread::Start(ThreadStartFunction function, uword parameter) {
|
|||
result = pthread_attr_setstacksize(&attr, Thread::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);
|
||||
|
|
|
@ -52,13 +52,17 @@ namespace bin {
|
|||
|
||||
class ThreadStartData {
|
||||
public:
|
||||
ThreadStartData(Thread::ThreadStartFunction function, uword parameter)
|
||||
: function_(function), parameter_(parameter) {}
|
||||
ThreadStartData(const char* name,
|
||||
Thread::ThreadStartFunction function,
|
||||
uword parameter)
|
||||
: name_(name), function_(function), parameter_(parameter) {}
|
||||
|
||||
const char* name() const { return name_; }
|
||||
Thread::ThreadStartFunction function() const { return function_; }
|
||||
uword parameter() const { return parameter_; }
|
||||
|
||||
private:
|
||||
const char* name_;
|
||||
Thread::ThreadStartFunction function_;
|
||||
uword parameter_;
|
||||
|
||||
|
@ -71,17 +75,23 @@ class ThreadStartData {
|
|||
static void* ThreadStart(void* data_ptr) {
|
||||
ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr);
|
||||
|
||||
const char* name = data->name();
|
||||
Thread::ThreadStartFunction function = data->function();
|
||||
uword parameter = data->parameter();
|
||||
delete data;
|
||||
|
||||
// Set the thread name.
|
||||
pthread_setname_np(name);
|
||||
|
||||
// Call the supplied thread start function handing it its parameters.
|
||||
function(parameter);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int Thread::Start(ThreadStartFunction function, uword parameter) {
|
||||
int Thread::Start(const char* name,
|
||||
ThreadStartFunction function,
|
||||
uword parameter) {
|
||||
pthread_attr_t attr;
|
||||
int result = pthread_attr_init(&attr);
|
||||
RETURN_ON_PTHREAD_FAILURE(result);
|
||||
|
@ -92,7 +102,7 @@ int Thread::Start(ThreadStartFunction function, uword parameter) {
|
|||
result = pthread_attr_setstacksize(&attr, Thread::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);
|
||||
|
|
|
@ -17,13 +17,17 @@ namespace bin {
|
|||
|
||||
class ThreadStartData {
|
||||
public:
|
||||
ThreadStartData(Thread::ThreadStartFunction function, uword parameter)
|
||||
: function_(function), parameter_(parameter) {}
|
||||
ThreadStartData(const char* name,
|
||||
Thread::ThreadStartFunction function,
|
||||
uword parameter)
|
||||
: name_(name), function_(function), parameter_(parameter) {}
|
||||
|
||||
const char* name() const { return name_; }
|
||||
Thread::ThreadStartFunction function() const { return function_; }
|
||||
uword parameter() const { return parameter_; }
|
||||
|
||||
private:
|
||||
const char* name_;
|
||||
Thread::ThreadStartFunction function_;
|
||||
uword parameter_;
|
||||
|
||||
|
@ -36,18 +40,24 @@ class ThreadStartData {
|
|||
static unsigned int __stdcall ThreadEntry(void* data_ptr) {
|
||||
ThreadStartData* data = reinterpret_cast<ThreadStartData*>(data_ptr);
|
||||
|
||||
const char* name = data->name();
|
||||
Thread::ThreadStartFunction function = data->function();
|
||||
uword parameter = data->parameter();
|
||||
delete data;
|
||||
|
||||
// Set the thread name.
|
||||
SetThreadDescription(GetCurrentThread(), reinterpret_cast<PCWSTR>(name));
|
||||
|
||||
// Call the supplied thread start function handing it its parameters.
|
||||
function(parameter);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Thread::Start(ThreadStartFunction function, uword parameter) {
|
||||
ThreadStartData* start_data = new ThreadStartData(function, parameter);
|
||||
int Thread::Start(const char* name,
|
||||
ThreadStartFunction function,
|
||||
uword parameter) {
|
||||
ThreadStartData* start_data = new ThreadStartData(name, function, parameter);
|
||||
uint32_t tid;
|
||||
uintptr_t thread = _beginthreadex(NULL, Thread::GetMaxStackSize(),
|
||||
ThreadEntry, start_data, 0, &tid);
|
||||
|
|
|
@ -119,6 +119,9 @@ static void* ThreadStart(void* data_ptr) {
|
|||
uword parameter = data->parameter();
|
||||
delete data;
|
||||
|
||||
// Set the thread name.
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
|
||||
// Create new OSThread object and set as TLS for new thread.
|
||||
OSThread* thread = OSThread::CreateOSThread();
|
||||
if (thread != NULL) {
|
||||
|
|
|
@ -12,9 +12,7 @@
|
|||
#include <errno.h> // NOLINT
|
||||
#include <zircon/status.h>
|
||||
#include <zircon/syscalls.h>
|
||||
#include <zircon/syscalls/object.h>
|
||||
#include <zircon/threads.h>
|
||||
#include <zircon/tls.h>
|
||||
#include <zircon/types.h>
|
||||
|
||||
#include "platform/address_sanitizer.h"
|
||||
|
|
|
@ -121,6 +121,9 @@ static void* ThreadStart(void* data_ptr) {
|
|||
uword parameter = data->parameter();
|
||||
delete data;
|
||||
|
||||
// Set the thread name.
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
|
||||
// Create new OSThread object and set as TLS for new thread.
|
||||
OSThread* thread = OSThread::CreateOSThread();
|
||||
if (thread != NULL) {
|
||||
|
|
|
@ -97,6 +97,9 @@ static void* ThreadStart(void* data_ptr) {
|
|||
uword parameter = data->parameter();
|
||||
delete data;
|
||||
|
||||
// Set the thread name.
|
||||
pthread_setname_np(name);
|
||||
|
||||
// Create new OSThread object and set as TLS for new thread.
|
||||
OSThread* thread = OSThread::CreateOSThread();
|
||||
if (thread != NULL) {
|
||||
|
|
|
@ -51,6 +51,9 @@ static unsigned int __stdcall ThreadEntry(void* data_ptr) {
|
|||
uword parameter = data->parameter();
|
||||
delete data;
|
||||
|
||||
// Set the thread name.
|
||||
SetThreadDescription(GetCurrentThread(), reinterpret_cast<PCWSTR>(name));
|
||||
|
||||
// Create new OSThread object and set as TLS for new thread.
|
||||
OSThread* thread = OSThread::CreateOSThread();
|
||||
if (thread != NULL) {
|
||||
|
|
Loading…
Reference in a new issue