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:
parent
89a7736bcf
commit
0e3d4fcbd4
|
@ -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();
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue