Skip to content

Commit acbfacf

Browse files
francoisdorayfdoray
authored andcommitted
[v8-tasks] Add source location to v8::TaskRunner, step 3/4. (nodejs#178)
Co-authored-by: François Doray <[email protected]>
1 parent adec83d commit acbfacf

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

src/node_platform.cc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,13 @@ void PerIsolatePlatformData::FlushTasks(uv_async_t* handle) {
245245
platform_data->FlushForegroundTasksInternal();
246246
}
247247

248-
void PerIsolatePlatformData::PostIdleTask(std::unique_ptr<v8::IdleTask> task) {
248+
void PerIsolatePlatformData::PostIdleTaskImpl(
249+
std::unique_ptr<v8::IdleTask> task, const v8::SourceLocation& location) {
249250
UNREACHABLE();
250251
}
251252

252-
void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) {
253+
void PerIsolatePlatformData::PostTaskImpl(std::unique_ptr<Task> task,
254+
const v8::SourceLocation& location) {
253255
if (flush_tasks_ == nullptr) {
254256
// V8 may post tasks during Isolate disposal. In that case, the only
255257
// sensible path forward is to discard the task.
@@ -259,8 +261,10 @@ void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) {
259261
uv_async_send(flush_tasks_);
260262
}
261263

262-
void PerIsolatePlatformData::PostDelayedTask(
263-
std::unique_ptr<Task> task, double delay_in_seconds) {
264+
void PerIsolatePlatformData::PostDelayedTaskImpl(
265+
std::unique_ptr<Task> task,
266+
double delay_in_seconds,
267+
const v8::SourceLocation& location) {
264268
if (flush_tasks_ == nullptr) {
265269
// V8 may post tasks during Isolate disposal. In that case, the only
266270
// sensible path forward is to discard the task.
@@ -274,14 +278,16 @@ void PerIsolatePlatformData::PostDelayedTask(
274278
uv_async_send(flush_tasks_);
275279
}
276280

277-
void PerIsolatePlatformData::PostNonNestableTask(std::unique_ptr<Task> task) {
278-
PostTask(std::move(task));
281+
void PerIsolatePlatformData::PostNonNestableTaskImpl(
282+
std::unique_ptr<Task> task, const v8::SourceLocation& location) {
283+
PostTaskImpl(std::move(task), location);
279284
}
280285

281-
void PerIsolatePlatformData::PostNonNestableDelayedTask(
286+
void PerIsolatePlatformData::PostNonNestableDelayedTaskImpl(
282287
std::unique_ptr<Task> task,
283-
double delay_in_seconds) {
284-
PostDelayedTask(std::move(task), delay_in_seconds);
288+
double delay_in_seconds,
289+
const v8::SourceLocation& location) {
290+
PostDelayedTaskImpl(std::move(task), delay_in_seconds, location);
285291
}
286292

287293
PerIsolatePlatformData::~PerIsolatePlatformData() {

src/node_platform.h

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
55

6+
#include <functional>
67
#include <queue>
78
#include <unordered_map>
89
#include <vector>
9-
#include <functional>
1010

1111
#include "libplatform/libplatform.h"
1212
#include "node.h"
@@ -50,27 +50,20 @@ struct DelayedTask {
5050
};
5151

5252
// This acts as the foreground task runner for a given Isolate.
53-
class PerIsolatePlatformData :
54-
public IsolatePlatformDelegate,
55-
public v8::TaskRunner,
56-
public std::enable_shared_from_this<PerIsolatePlatformData> {
53+
class PerIsolatePlatformData
54+
: public IsolatePlatformDelegate,
55+
public v8::TaskRunner,
56+
public std::enable_shared_from_this<PerIsolatePlatformData> {
5757
public:
5858
PerIsolatePlatformData(v8::Isolate* isolate, uv_loop_t* loop);
5959
~PerIsolatePlatformData() override;
6060

6161
std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner() override;
62-
void PostTask(std::unique_ptr<v8::Task> task) override;
63-
void PostIdleTask(std::unique_ptr<v8::IdleTask> task) override;
64-
void PostDelayedTask(std::unique_ptr<v8::Task> task,
65-
double delay_in_seconds) override;
6662
bool IdleTasksEnabled() override { return false; }
6763

6864
// Non-nestable tasks are treated like regular tasks.
6965
bool NonNestableTasksEnabled() const override { return true; }
7066
bool NonNestableDelayedTasksEnabled() const override { return true; }
71-
void PostNonNestableTask(std::unique_ptr<v8::Task> task) override;
72-
void PostNonNestableDelayedTask(std::unique_ptr<v8::Task> task,
73-
double delay_in_seconds) override;
7467

7568
void AddShutdownCallback(void (*callback)(void*), void* data);
7669
void Shutdown();
@@ -83,6 +76,21 @@ class PerIsolatePlatformData :
8376
const uv_loop_t* event_loop() const { return loop_; }
8477

8578
private:
79+
// v8::TaskRunner implementation.
80+
void PostTaskImpl(std::unique_ptr<v8::Task> task,
81+
const v8::SourceLocation& location) override;
82+
void PostDelayedTaskImpl(std::unique_ptr<v8::Task> task,
83+
double delay_in_seconds,
84+
const v8::SourceLocation& location) override;
85+
void PostIdleTaskImpl(std::unique_ptr<v8::IdleTask> task,
86+
const v8::SourceLocation& location) override;
87+
void PostNonNestableTaskImpl(std::unique_ptr<v8::Task> task,
88+
const v8::SourceLocation& location) override;
89+
void PostNonNestableDelayedTaskImpl(
90+
std::unique_ptr<v8::Task> task,
91+
double delay_in_seconds,
92+
const v8::SourceLocation& location) override;
93+
8694
void DeleteFromScheduledTasks(DelayedTask* task);
8795
void DecreaseHandleCount();
8896

@@ -107,7 +115,7 @@ class PerIsolatePlatformData :
107115
TaskQueue<DelayedTask> foreground_delayed_tasks_;
108116

109117
// Use a custom deleter because libuv needs to close the handle first.
110-
typedef std::unique_ptr<DelayedTask, void(*)(DelayedTask*)>
118+
typedef std::unique_ptr<DelayedTask, void (*)(DelayedTask*)>
111119
DelayedTaskPointer;
112120
std::vector<DelayedTaskPointer> scheduled_delayed_tasks_;
113121
};
@@ -118,8 +126,7 @@ class WorkerThreadsTaskRunner {
118126
explicit WorkerThreadsTaskRunner(int thread_pool_size);
119127

120128
void PostTask(std::unique_ptr<v8::Task> task);
121-
void PostDelayedTask(std::unique_ptr<v8::Task> task,
122-
double delay_in_seconds);
129+
void PostDelayedTask(std::unique_ptr<v8::Task> task, double delay_in_seconds);
123130

124131
void BlockingDrain();
125132
void Shutdown();
@@ -171,7 +178,8 @@ class NodePlatform : public MultiIsolatePlatform {
171178

172179
void UnregisterIsolate(v8::Isolate* isolate) override;
173180
void AddIsolateFinishedCallback(v8::Isolate* isolate,
174-
void (*callback)(void*), void* data) override;
181+
void (*callback)(void*),
182+
void* data) override;
175183

176184
std::shared_ptr<v8::TaskRunner> GetForegroundTaskRunner(
177185
v8::Isolate* isolate) override;
@@ -184,8 +192,8 @@ class NodePlatform : public MultiIsolatePlatform {
184192
std::shared_ptr<PerIsolatePlatformData> ForNodeIsolate(v8::Isolate* isolate);
185193

186194
Mutex per_isolate_mutex_;
187-
using DelegatePair = std::pair<
188-
IsolatePlatformDelegate*, std::shared_ptr<PerIsolatePlatformData>>;
195+
using DelegatePair = std::pair<IsolatePlatformDelegate*,
196+
std::shared_ptr<PerIsolatePlatformData>>;
189197
std::unordered_map<v8::Isolate*, DelegatePair> per_isolate_;
190198

191199
v8::TracingController* tracing_controller_;

0 commit comments

Comments
 (0)