Commit 44f46540 authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[Jobs API] Lockless CancelAndDetach.

Wasm wants to uses a CancelAndDetach + shared_ptr pattern that can cause
CancelAndDetach to be called within GetMaxConcurrency(). This causes
recursive lock errors. CancelAndDetach doesn't need a lock since state_
is atomic; making it lockless allows this use case.

The current wasm alternative is to hold a vector of JobHandle until the
renderer is teared down; this causes a growing 'live' leak.

Change-Id: I50e220fc87136739bd3641a2a6d5fad1fe376f9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2508335
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822870}
parent d6ee8662
...@@ -149,11 +149,10 @@ bool JobTaskSource::RunJoinTask() { ...@@ -149,11 +149,10 @@ bool JobTaskSource::RunJoinTask() {
} }
void JobTaskSource::Cancel(TaskSource::Transaction* transaction) { void JobTaskSource::Cancel(TaskSource::Transaction* transaction) {
CheckedAutoLock auto_lock(worker_lock_);
// Sets the kCanceledMask bit on |state_| so that further calls to // Sets the kCanceledMask bit on |state_| so that further calls to
// WillRunTask() never succeed. std::memory_order_relaxed is sufficient // WillRunTask() never succeed. std::memory_order_relaxed without a lock is
// because this task source never needs to be re-enqueued after Cancel(). // safe because this task source never needs to be re-enqueued after Cancel().
state_.Cancel(); TS_UNCHECKED_READ(state_).Cancel();
} }
// EXCLUSIVE_LOCK_REQUIRED(worker_lock_) // EXCLUSIVE_LOCK_REQUIRED(worker_lock_)
......
...@@ -192,7 +192,7 @@ class BASE_EXPORT JobTaskSource : public TaskSource { ...@@ -192,7 +192,7 @@ class BASE_EXPORT JobTaskSource : public TaskSource {
mutable CheckedLock worker_lock_{UniversalSuccessor()}; mutable CheckedLock worker_lock_{UniversalSuccessor()};
// Current atomic state (atomic despite the lock to allow optimistic reads // Current atomic state (atomic despite the lock to allow optimistic reads
// without the lock). // and cancellation without the lock).
State state_ GUARDED_BY(worker_lock_); State state_ GUARDED_BY(worker_lock_);
// Normally, |join_flag_| is protected by |lock_|, except in ShouldYield() // Normally, |join_flag_| is protected by |lock_|, except in ShouldYield()
// hence the use of atomics. // hence the use of atomics.
......
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