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:
VTS tests after this fix: