I believe the value returned by value() resets when we call setValue() with the maximum (due to auto-reset). I have been unable to test this because I can't reproduce the issue, which is described at https://bugs.dolphin-emu.org/issues/12158#note-9.
This workaround is not timing sensitive, unlike the old one. Hopefully fixes https://bugs.dolphin-emu.org/issues/12158 and https://bugs.dolphin-emu.org/issues/12180.