dawn_node: Prevent setImmediate() being queued multiple times

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 <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-10-19 18:42:29 +00:00 committed by Dawn LUCI CQ
parent 89a7736bcf
commit 0e3d4fcbd4
2 changed files with 6 additions and 0 deletions

View File

@ -37,6 +37,10 @@ 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>()
@ -44,6 +48,7 @@ namespace wgpu { namespace binding {
// 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();

View File

@ -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