[vm] Add missing Dart_ThreadStartCallback.

For symmetry with Dart_ThreadExitCallback. Can be used by an embedder to change thread priority or attach native resources to the thread.

TEST=ci
Change-Id: Ic8eaba7204d0be42db26523b62cbfac3ecb7151f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/227661
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak
2022-01-19 23:14:36 +00:00
committed by Commit Bot
parent 75247601ef
commit 4088cd083d
6 changed files with 47 additions and 14 deletions
+1
View File
@@ -380,6 +380,7 @@ static int Main(int argc, const char** argv) {
/*shutdown_isolate=*/nullptr,
/*cleanup_isolate=*/nullptr,
/*cleanup_group=*/CleanupIsolateGroup,
/*thread_start=*/nullptr,
/*thread_exit=*/nullptr, dart::bin::DartUtils::OpenFile,
dart::bin::DartUtils::ReadFile, dart::bin::DartUtils::WriteFile,
dart::bin::DartUtils::CloseFile, /*entropy_source=*/nullptr,
+11 -1
View File
@@ -756,6 +756,15 @@ typedef void (*Dart_IsolateCleanupCallback)(void* isolate_group_data,
*/
typedef void (*Dart_IsolateGroupCleanupCallback)(void* isolate_group_data);
/**
* A thread start callback function.
* This callback, provided by the embedder, is called after a thread in the
* vm thread pool starts.
* This function could be used to adjust thread priority or attach native
* resources to the thread.
*/
typedef void (*Dart_ThreadStartCallback)(void);
/**
* A thread death callback function.
* This callback, provided by the embedder, is called before a thread in the
@@ -840,7 +849,7 @@ typedef Dart_Handle (*Dart_GetVMServiceAssetsArchive)(void);
* The current version of the Dart_InitializeFlags. Should be incremented every
* time Dart_InitializeFlags changes in a binary incompatible way.
*/
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000005)
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000006)
/** Forward declaration */
struct Dart_CodeObserver;
@@ -966,6 +975,7 @@ typedef struct {
*/
Dart_IsolateGroupCleanupCallback cleanup_group;
Dart_ThreadStartCallback thread_start;
Dart_ThreadExitCallback thread_exit;
Dart_FileOpenCallback file_open;
Dart_FileReadCallback file_read;
+7 -3
View File
@@ -63,6 +63,7 @@ ThreadPool* Dart::thread_pool_ = NULL;
DebugInfo* Dart::pprof_symbol_generator_ = NULL;
ReadOnlyHandles* Dart::predefined_handles_ = NULL;
Snapshot::Kind Dart::vm_snapshot_kind_ = Snapshot::kInvalid;
Dart_ThreadStartCallback Dart::thread_start_callback_ = NULL;
Dart_ThreadExitCallback Dart::thread_exit_callback_ = NULL;
Dart_FileOpenCallback Dart::file_open_callback_ = NULL;
Dart_FileReadCallback Dart::file_read_callback_ = NULL;
@@ -254,6 +255,7 @@ char* Dart::DartInit(const uint8_t* vm_isolate_snapshot,
Dart_IsolateShutdownCallback shutdown,
Dart_IsolateCleanupCallback cleanup,
Dart_IsolateGroupCleanupCallback cleanup_group,
Dart_ThreadStartCallback thread_start,
Dart_ThreadExitCallback thread_exit,
Dart_FileOpenCallback file_open,
Dart_FileReadCallback file_read,
@@ -296,6 +298,7 @@ char* Dart::DartInit(const uint8_t* vm_isolate_snapshot,
UntaggedFrame::Init();
set_thread_start_callback(thread_start);
set_thread_exit_callback(thread_exit);
SetFileCallbacks(file_open, file_read, file_write, file_close);
set_entropy_source_callback(entropy_source);
@@ -532,6 +535,7 @@ char* Dart::Init(const uint8_t* vm_isolate_snapshot,
Dart_IsolateShutdownCallback shutdown,
Dart_IsolateCleanupCallback cleanup,
Dart_IsolateGroupCleanupCallback cleanup_group,
Dart_ThreadStartCallback thread_start,
Dart_ThreadExitCallback thread_exit,
Dart_FileOpenCallback file_open,
Dart_FileReadCallback file_read,
@@ -552,9 +556,9 @@ char* Dart::Init(const uint8_t* vm_isolate_snapshot,
char* retval =
DartInit(vm_isolate_snapshot, instructions_snapshot, create_group,
initialize_isolate, shutdown, cleanup, cleanup_group,
thread_exit, file_open, file_read, file_write, file_close,
entropy_source, get_service_assets, start_kernel_isolate,
observer, post_task, post_task_data);
thread_start, thread_exit, file_open, file_read, file_write,
file_close, entropy_source, get_service_assets,
start_kernel_isolate, observer, post_task, post_task_data);
if (retval != NULL) {
init_state_.ResetInitializing();
return retval;
+9
View File
@@ -36,6 +36,7 @@ class Dart : public AllStatic {
Dart_IsolateShutdownCallback shutdown,
Dart_IsolateCleanupCallback cleanup,
Dart_IsolateGroupCleanupCallback cleanup_group,
Dart_ThreadStartCallback thread_start,
Dart_ThreadExitCallback thread_exit,
Dart_FileOpenCallback file_open,
Dart_FileReadCallback file_read,
@@ -119,6 +120,12 @@ class Dart : public AllStatic {
Snapshot::Kind kind);
static Snapshot::Kind vm_snapshot_kind() { return vm_snapshot_kind_; }
static Dart_ThreadStartCallback thread_start_callback() {
return thread_start_callback_;
}
static void set_thread_start_callback(Dart_ThreadStartCallback cback) {
thread_start_callback_ = cback;
}
static Dart_ThreadExitCallback thread_exit_callback() {
return thread_exit_callback_;
}
@@ -176,6 +183,7 @@ class Dart : public AllStatic {
Dart_IsolateShutdownCallback shutdown,
Dart_IsolateCleanupCallback cleanup,
Dart_IsolateGroupCleanupCallback cleanup_group,
Dart_ThreadStartCallback thread_start,
Dart_ThreadExitCallback thread_exit,
Dart_FileOpenCallback file_open,
Dart_FileReadCallback file_read,
@@ -199,6 +207,7 @@ class Dart : public AllStatic {
static DebugInfo* pprof_symbol_generator_;
static ReadOnlyHandles* predefined_handles_;
static Snapshot::Kind vm_snapshot_kind_;
static Dart_ThreadStartCallback thread_start_callback_;
static Dart_ThreadExitCallback thread_exit_callback_;
static Dart_FileOpenCallback file_open_callback_;
static Dart_FileReadCallback file_read_callback_;
+9 -8
View File
@@ -1206,14 +1206,15 @@ DART_EXPORT char* Dart_Initialize(Dart_InitializeParams* params) {
"Invalid Dart_InitializeParams version.");
}
return Dart::Init(
params->vm_snapshot_data, params->vm_snapshot_instructions,
params->create_group, params->initialize_isolate,
params->shutdown_isolate, params->cleanup_isolate, params->cleanup_group,
params->thread_exit, params->file_open, params->file_read,
params->file_write, params->file_close, params->entropy_source,
params->get_service_assets, params->start_kernel_isolate,
params->code_observer, params->post_task, params->post_task_data);
return Dart::Init(params->vm_snapshot_data, params->vm_snapshot_instructions,
params->create_group, params->initialize_isolate,
params->shutdown_isolate, params->cleanup_isolate,
params->cleanup_group, params->thread_start,
params->thread_exit, params->file_open, params->file_read,
params->file_write, params->file_close,
params->entropy_source, params->get_service_assets,
params->start_kernel_isolate, params->code_observer,
params->post_task, params->post_task_data);
}
DART_EXPORT char* Dart_Cleanup() {
+10 -2
View File
@@ -317,6 +317,13 @@ void ThreadPool::Worker::StartThread() {
}
void ThreadPool::Worker::Main(uword args) {
// Call the thread start hook here to notify the embedder that the
// thread pool thread has started.
Dart_ThreadStartCallback start_cb = Dart::thread_start_callback();
if (start_cb != nullptr) {
start_cb();
}
OSThread* os_thread = OSThread::Current();
ASSERT(os_thread != nullptr);
@@ -343,8 +350,9 @@ void ThreadPool::Worker::Main(uword args) {
// Call the thread exit hook here to notify the embedder that the
// thread pool thread is exiting.
if (Dart::thread_exit_callback() != NULL) {
(*Dart::thread_exit_callback())();
Dart_ThreadExitCallback exit_cb = Dart::thread_exit_callback();
if (exit_cb != nullptr) {
exit_cb();
}
}