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.
This issue was discovered during VTS testing, SetVsyncEnabled testcase occasionally crashed drm_hwcomposer process and that created invalid state for any following testcases:
Module | Passed | Failed | Total Tests |
---|---|---|---|
arm64-v8a VtsHalGraphicsComposerV2_1Target | 31 | 22 | 53 |
armeabi-v7a VtsHalGraphicsComposerV2_1Target | 31 | 22 | 53 |
VTS tests after this fix:
Module | Passed | Failed | Total Tests |
---|---|---|---|
arm64-v8a VtsHalGraphicsComposerV2_1Target | 51 | 2 | 53 |
armeabi-v7a VtsHalGraphicsComposerV2_1Target | 51 | 2 | 53 |