Skip to content

Commit 7812c93

Browse files
addaleaxMylesBorins
authored andcommitted
deps: cherry-pick c690f54d95802 from V8 upstream
Original commit message: [platform] Add TaskRunner to the platform API With the existing platform API it is not possible to post foreground tasks from background tasks. This is, however, required to implement asynchronous compilation for WebAssembly. With this CL we add the concept of a TaskRunner to the platform API. The TaskRunner contains all data needed to post a foreground task and can be used both from a foreground task and a background task. Eventually the TaskRunner should replace the existing API. In addition, this CL contains a default implementation of the TaskRunner. This implementation has tempory workaround for platforms which do not provide a TaskRunner implementation yet. This default implementation should be deleted again when all platforms provide a TaskRunner implementation. [email protected] Cq-Include-Trybots: master.tryserver.chromium.linux:linux_chromium_rel_ng Change-Id: I6ea4a1c9da1eb9a19e8ce8f2163000dbc2598802 Reviewed-on: https://chromium-review.googlesource.com/741588 Commit-Queue: Andreas Haas <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Cr-Commit-Position: refs/heads/master@{#49041} Refs: v8/v8@c690f54 PR-URL: #17134 Fixes: nodejs/node-v8#24 Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2e31126 commit 7812c93

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

deps/v8/include/v8-platform.h

+67
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,51 @@ class IdleTask {
3636
virtual void Run(double deadline_in_seconds) = 0;
3737
};
3838

39+
/**
40+
* A TaskRunner allows scheduling of tasks. The TaskRunner may still be used to
41+
* post tasks after the isolate gets destructed, but these tasks may not get
42+
* executed anymore. All tasks posted to a given TaskRunner will be invoked in
43+
* sequence. Tasks can be posted from any thread.
44+
*/
45+
class TaskRunner {
46+
public:
47+
/**
48+
* Schedules a task to be invoked by this TaskRunner. The TaskRunner
49+
* implementation takes ownership of |task|.
50+
*/
51+
virtual void PostTask(std::unique_ptr<Task> task) = 0;
52+
53+
/**
54+
* Schedules a task to be invoked by this TaskRunner. The task is scheduled
55+
* after the given number of seconds |delay_in_seconds|. The TaskRunner
56+
* implementation takes ownership of |task|.
57+
*/
58+
virtual void PostDelayedTask(std::unique_ptr<Task> task,
59+
double delay_in_seconds) = 0;
60+
61+
/**
62+
* Schedules an idle task to be invoked by this TaskRunner. The task is
63+
* scheduled when the embedder is idle. Requires that
64+
* TaskRunner::SupportsIdleTasks(isolate) is true. Idle tasks may be reordered
65+
* relative to other task types and may be starved for an arbitrarily long
66+
* time if no idle time is available. The TaskRunner implementation takes
67+
* ownership of |task|.
68+
*/
69+
virtual void PostIdleTask(std::unique_ptr<IdleTask> task) = 0;
70+
71+
/**
72+
* Returns true if idle tasks are enabled for this TaskRunner.
73+
*/
74+
virtual bool IdleTasksEnabled() = 0;
75+
76+
TaskRunner() = default;
77+
virtual ~TaskRunner() = default;
78+
79+
private:
80+
TaskRunner(const TaskRunner&) = delete;
81+
TaskRunner& operator=(const TaskRunner&) = delete;
82+
};
83+
3984
/**
4085
* The interface represents complex arguments to trace events.
4186
*/
@@ -150,6 +195,28 @@ class Platform {
150195
*/
151196
virtual size_t NumberOfAvailableBackgroundThreads() { return 0; }
152197

198+
/**
199+
* Returns a TaskRunner which can be used to post a task on the foreground.
200+
* This function should only be called from a foreground thread.
201+
*/
202+
virtual std::unique_ptr<v8::TaskRunner> GetForegroundTaskRunner(
203+
Isolate* isolate) {
204+
// TODO(ahaas): Make this function abstract after it got implemented on all
205+
// platforms.
206+
return {};
207+
}
208+
209+
/**
210+
* Returns a TaskRunner which can be used to post a task on a background.
211+
* This function should only be called from a foreground thread.
212+
*/
213+
virtual std::unique_ptr<v8::TaskRunner> GetBackgroundTaskRunner(
214+
Isolate* isolate) {
215+
// TODO(ahaas): Make this function abstract after it got implemented on all
216+
// platforms.
217+
return {};
218+
}
219+
153220
/**
154221
* Schedules a task to be invoked on a background thread. |expected_runtime|
155222
* indicates that the task will run a long time. The Platform implementation

0 commit comments

Comments
 (0)