[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/+/3644801 Reviewed-by: Andreas Haas <ahaas@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/main@{#80611}
This commit is contained in:
parent
c3107f0692
commit
7eacc4d552
@ -158,9 +158,10 @@ class TaskRunner {
|
||||
class JobDelegate {
|
||||
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
|
||||
* YieldIfNeeded()) as often as is reasonable.
|
||||
* After this method returned true, ShouldYield must not be called again.
|
||||
*/
|
||||
virtual bool ShouldYield() = 0;
|
||||
|
||||
|
@ -29,8 +29,14 @@ class V8_PLATFORM_EXPORT DefaultJobState
|
||||
outer_->NotifyConcurrencyIncrease();
|
||||
}
|
||||
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.
|
||||
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;
|
||||
bool IsJoiningThread() const override { return is_joining_thread_; }
|
||||
@ -42,6 +48,7 @@ class V8_PLATFORM_EXPORT DefaultJobState
|
||||
DefaultJobState* outer_;
|
||||
uint8_t task_id_ = kInvalidTaskId;
|
||||
bool is_joining_thread_;
|
||||
bool was_told_to_yield_ = false;
|
||||
};
|
||||
|
||||
DefaultJobState(Platform* platform, std::unique_ptr<JobTask> job_task,
|
||||
|
Loading…
Reference in New Issue
Block a user