Skip to content

Commit

Permalink
dawn_node: Prevent setImmediate() being queued multiple times
Browse files Browse the repository at this point in the history
The AsyncRunner will enqueue a call to `Device::Tick()` when the runner count moves from 0 async tasks to 1.

It has been observed that some 'async' tasks are actually synchronious, which results in multiple tick callbacks being enqueued before the first has a chance to run.
Fix this by using another boolean to track whether the function has been queued.

Bug: dawn:1127
Change-Id: I7dd81d33d601bf1d3cefb5c4dad6c237883e51ee
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/66820
Auto-Submit: Ben Clayton <[email protected]>
Reviewed-by: Antonio Maiorano <[email protected]>
Commit-Queue: Ben Clayton <[email protected]>
  • Loading branch information
ben-clayton authored and Dawn LUCI CQ committed Oct 19, 2021
1 parent 89a7736 commit 0e3d4fc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/dawn_node/binding/AsyncRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@ namespace wgpu { namespace binding {
void AsyncRunner::QueueTick() {
// TODO(crbug.com/dawn/1127): We probably want to reduce the frequency at which this gets
// called.
if (tick_queued_) {
return;
}
tick_queued_ = true;
env_.Global()
.Get("setImmediate")
.As<Napi::Function>()
.Call({
// TODO(crbug.com/dawn/1127): Create once, reuse.
Napi::Function::New(env_,
[this](const Napi::CallbackInfo&) {
tick_queued_ = false;
if (count_ > 0) {
device_.Tick();
QueueTick();
Expand Down
1 change: 1 addition & 0 deletions src/dawn_node/binding/AsyncRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace wgpu { namespace binding {
Napi::Env env_;
wgpu::Device const device_;
uint64_t count_ = 0;
bool tick_queued_ = false;
};

// AsyncTask is a RAII helper for calling AsyncRunner::Begin() on construction, and
Expand Down

0 comments on commit 0e3d4fc

Please sign in to comment.