Commit 69951fa7 authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[Jobs API]: Expose JobDelegate::IsJoiningThread.

To let the user do special handling on the main thread e.g. Scavenging
uses different tracing categories for background/foreground threads.

Change-Id: I6c9187fd6201b5b81cd83727727fda49fcf7ff68
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2405797Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69978}
parent 0eb3e25d
......@@ -177,6 +177,13 @@ class JobDelegate {
* reused by a different thread after a worker_task returns.
*/
virtual uint8_t GetTaskId() = 0;
/**
* Returns true if the current task is called from the thread currently
* running JobHandle::Join().
* TODO(etiennep): Make pure virtual once custom embedders implement it.
*/
virtual bool IsJoiningThread() const { return false; }
};
/**
......
......@@ -114,6 +114,7 @@ std::unique_ptr<cppgc::JobHandle> DefaultPlatform::PostJob(
bool ShouldYield() override { return false; }
void NotifyConcurrencyIncrease() override {}
uint8_t GetTaskId() override { return 0; }
bool IsJoiningThread() const override { return false; }
} delegate;
if (task) task->Run(&delegate);
......
......@@ -104,7 +104,7 @@ void DefaultJobState::Join() {
++active_workers_;
can_run = WaitForParticipationOpportunityLockRequired();
}
DefaultJobState::JobDelegate delegate(this);
DefaultJobState::JobDelegate delegate(this, true);
while (can_run) {
job_task_->Run(&delegate);
base::MutexGuard guard(&mutex_);
......
......@@ -21,7 +21,8 @@ class V8_PLATFORM_EXPORT DefaultJobState
public:
class JobDelegate : public v8::JobDelegate {
public:
explicit JobDelegate(DefaultJobState* outer) : outer_(outer) {}
explicit JobDelegate(DefaultJobState* outer, bool is_joining_thread = false)
: outer_(outer), is_joining_thread_(is_joining_thread) {}
~JobDelegate();
void NotifyConcurrencyIncrease() override {
......@@ -32,6 +33,7 @@ class V8_PLATFORM_EXPORT DefaultJobState
return outer_->is_canceled_.load(std::memory_order_relaxed);
}
uint8_t GetTaskId() override;
bool IsJoiningThread() const override { return is_joining_thread_; }
private:
static constexpr uint8_t kInvalidTaskId =
......@@ -39,6 +41,7 @@ class V8_PLATFORM_EXPORT DefaultJobState
DefaultJobState* outer_;
uint8_t task_id_ = kInvalidTaskId;
bool is_joining_thread_;
};
DefaultJobState(Platform* platform, std::unique_ptr<JobTask> job_task,
......
......@@ -96,6 +96,7 @@ class TestPlatform : public Platform {
bool ShouldYield() override { return false; }
void NotifyConcurrencyIncrease() override {}
uint8_t GetTaskId() override { return 0; }
bool IsJoiningThread() const override { return false; }
} delegate;
if (task_) task_->Run(&delegate);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment