summaryrefslogtreecommitdiff
path: root/src/node_platform.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_platform.h')
-rw-r--r--src/node_platform.h48
1 files changed, 39 insertions, 9 deletions
diff --git a/src/node_platform.h b/src/node_platform.h
index 48301a05a1..e5253cac10 100644
--- a/src/node_platform.h
+++ b/src/node_platform.h
@@ -43,17 +43,22 @@ struct DelayedTask {
std::unique_ptr<v8::Task> task;
uv_timer_t timer;
double timeout;
- PerIsolatePlatformData* platform_data;
+ std::shared_ptr<PerIsolatePlatformData> platform_data;
};
-class PerIsolatePlatformData {
+// This acts as the foreground task runner for a given Isolate.
+class PerIsolatePlatformData :
+ public v8::TaskRunner,
+ public std::enable_shared_from_this<PerIsolatePlatformData> {
public:
PerIsolatePlatformData(v8::Isolate* isolate, uv_loop_t* loop);
~PerIsolatePlatformData();
- void CallOnForegroundThread(std::unique_ptr<v8::Task> task);
- void CallDelayedOnForegroundThread(std::unique_ptr<v8::Task> task,
- double delay_in_seconds);
+ void PostTask(std::unique_ptr<v8::Task> task) override;
+ void PostIdleTask(std::unique_ptr<v8::IdleTask> task) override;
+ void PostDelayedTask(std::unique_ptr<v8::Task> task,
+ double delay_in_seconds) override;
+ bool IdleTasksEnabled() override { return false; };
void Shutdown();
@@ -84,6 +89,26 @@ class PerIsolatePlatformData {
std::vector<DelayedTaskPointer> scheduled_delayed_tasks_;
};
+// This acts as the single background task runner for all Isolates.
+class BackgroundTaskRunner : public v8::TaskRunner {
+ public:
+ explicit BackgroundTaskRunner(int thread_pool_size);
+
+ void PostTask(std::unique_ptr<v8::Task> task) override;
+ void PostIdleTask(std::unique_ptr<v8::IdleTask> task) override;
+ void PostDelayedTask(std::unique_ptr<v8::Task> task,
+ double delay_in_seconds) override;
+ bool IdleTasksEnabled() override { return false; };
+
+ void BlockingDrain();
+ void Shutdown();
+
+ size_t NumberOfAvailableBackgroundThreads() const;
+ private:
+ TaskQueue<v8::Task> background_tasks_;
+ std::vector<std::unique_ptr<uv_thread_t>> threads_;
+};
+
class NodePlatform : public MultiIsolatePlatform {
public:
NodePlatform(int thread_pool_size, v8::TracingController* tracing_controller);
@@ -109,15 +134,20 @@ class NodePlatform : public MultiIsolatePlatform {
void RegisterIsolate(IsolateData* isolate_data, uv_loop_t* loop) override;
void UnregisterIsolate(IsolateData* isolate_data) override;
+ std::shared_ptr<v8::TaskRunner> GetBackgroundTaskRunner(
+ v8::Isolate* isolate) override;
+ std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
+ v8::Isolate* isolate) override;
+
private:
- PerIsolatePlatformData* ForIsolate(v8::Isolate* isolate);
+ std::shared_ptr<PerIsolatePlatformData> ForIsolate(v8::Isolate* isolate);
Mutex per_isolate_mutex_;
- std::unordered_map<v8::Isolate*, PerIsolatePlatformData*> per_isolate_;
- TaskQueue<v8::Task> background_tasks_;
- std::vector<std::unique_ptr<uv_thread_t>> threads_;
+ std::unordered_map<v8::Isolate*,
+ std::shared_ptr<PerIsolatePlatformData>> per_isolate_;
std::unique_ptr<v8::TracingController> tracing_controller_;
+ std::shared_ptr<BackgroundTaskRunner> background_task_runner_;
};
} // namespace node