Commit 7eacc4d5 authored by Clemens Backes's avatar Clemens Backes Committed by V8 LUCI CQ

[API] Enforce that ShouldYield == true is respected

There is a DCHECK in the gin platform that {ShouldYield} is not called
again after it already returned {true}.
This CL adds a similar DCHECK to the default platform to catch bugs
earlier (in d8).

R=ahaas@chromium.org, mlippautz@chromium.org

Bug: chromium:1277962
Change-Id: I4dc9d880cf6d36e3e497c5324aaf44889fe7fcee
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3644801Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80611}
parent c3107f06
...@@ -158,9 +158,10 @@ class TaskRunner { ...@@ -158,9 +158,10 @@ class TaskRunner {
class JobDelegate { class JobDelegate {
public: public:
/** /**
* Returns true if this thread should return from the worker task on the * Returns true if this thread *must* return from the worker task on the
* current thread ASAP. Workers should periodically invoke ShouldYield (or * current thread ASAP. Workers should periodically invoke ShouldYield (or
* YieldIfNeeded()) as often as is reasonable. * YieldIfNeeded()) as often as is reasonable.
* After this method returned true, ShouldYield must not be called again.
*/ */
virtual bool ShouldYield() = 0; virtual bool ShouldYield() = 0;
......
...@@ -29,8 +29,14 @@ class V8_PLATFORM_EXPORT DefaultJobState ...@@ -29,8 +29,14 @@ class V8_PLATFORM_EXPORT DefaultJobState
outer_->NotifyConcurrencyIncrease(); outer_->NotifyConcurrencyIncrease();
} }
bool ShouldYield() override { bool ShouldYield() override {
// After {ShouldYield} returned true, the job is expected to return and
// not call {ShouldYield} again. This resembles a similar DCHECK in the
// gin platform.
DCHECK(!was_told_to_yield_);
// Thread-safe but may return an outdated result. // Thread-safe but may return an outdated result.
return outer_->is_canceled_.load(std::memory_order_relaxed); was_told_to_yield_ |=
outer_->is_canceled_.load(std::memory_order_relaxed);
return was_told_to_yield_;
} }
uint8_t GetTaskId() override; uint8_t GetTaskId() override;
bool IsJoiningThread() const override { return is_joining_thread_; } bool IsJoiningThread() const override { return is_joining_thread_; }
...@@ -42,6 +48,7 @@ class V8_PLATFORM_EXPORT DefaultJobState ...@@ -42,6 +48,7 @@ class V8_PLATFORM_EXPORT DefaultJobState
DefaultJobState* outer_; DefaultJobState* outer_;
uint8_t task_id_ = kInvalidTaskId; uint8_t task_id_ = kInvalidTaskId;
bool is_joining_thread_; bool is_joining_thread_;
bool was_told_to_yield_ = false;
}; };
DefaultJobState(Platform* platform, std::unique_ptr<JobTask> job_task, DefaultJobState(Platform* platform, std::unique_ptr<JobTask> job_task,
......
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