diff --git a/src/wasm/wasm-serialization.cc b/src/wasm/wasm-serialization.cc index 3cf567895e..b7efe7cb82 100644 --- a/src/wasm/wasm-serialization.cc +++ b/src/wasm/wasm-serialization.cc @@ -588,9 +588,10 @@ class DeserializeCodeTask : public JobTask { void Run(JobDelegate* delegate) override { CodeSpaceWriteScope code_space_write_scope(deserializer_->native_module_); - do { + bool finished = false; + while (!finished) { // Repeatedly publish everything that was copied already. - TryPublishing(delegate); + finished = TryPublishing(delegate); auto batch = reloc_queue_->Pop(); if (batch.empty()) break; @@ -599,7 +600,7 @@ class DeserializeCodeTask : public JobTask { } publish_queue_.Add(std::move(batch)); delegate->NotifyConcurrencyIncrease(); - } while (!delegate->ShouldYield()); + } } size_t GetMaxConcurrency(size_t /* worker_count */) const override { @@ -611,9 +612,9 @@ class DeserializeCodeTask : public JobTask { } private: - void TryPublishing(JobDelegate* delegate) { + bool TryPublishing(JobDelegate* delegate) { // Publishing is sequential, so only start publishing if no one else is. - if (publishing_.exchange(true, std::memory_order_relaxed)) return; + if (publishing_.exchange(true, std::memory_order_relaxed)) return false; WasmCodeRefScope code_scope; while (true) { @@ -625,13 +626,14 @@ class DeserializeCodeTask : public JobTask { yield = delegate->ShouldYield(); } publishing_.store(false, std::memory_order_relaxed); - if (yield) break; + if (yield) return true; // After finishing publishing, check again if new work arrived in the mean // time. If so, continue publishing. if (publish_queue_.NumBatches() == 0) break; if (publishing_.exchange(true, std::memory_order_relaxed)) break; // We successfully reset {publishing_} from {false} to {true}. } + return false; } NativeModuleDeserializer* const deserializer_;