drm_hwcomposer: Add check to vsync routine to avoid crash on callback
Vsync could be disabled during routine being running and this could
potentially lead to crash on callback invocation. Crash happens if
VSyncControl(false) was called when Routine has cached callback and
unlocked mutex but haven't callback yet. At this point we can't be
sure that callback is still valid so invoking it is incorrect
behaviour.
Second check if vsync is enabled drastically shortens window when we
could go into invalid state, from the whole vblank invocation to
several machine instructions between check and invocation.
Please note that we can't check against cached value in this case,
therefore operations on this flag should be atomic instead.
Signed-off-by: Roman Kovalivskyi <roman.kovalivskyi@globallogic.com>
diff --git a/include/vsyncworker.h b/include/vsyncworker.h
index b2bca9d..96f7432 100644
--- a/include/vsyncworker.h
+++ b/include/vsyncworker.h
@@ -60,7 +60,7 @@
std::shared_ptr<VsyncCallback> callback_ = NULL;
int display_;
- bool enabled_;
+ std::atomic_bool enabled_;
int64_t last_timestamp_;
};
} // namespace android