Fix a race condition in RecurrentTimer.

Previously RecurrentTimer might not exit correctly if the mStopRequested
is set to true after we check for the value in the loop, but before
we start the wait. We will notify before we start waiting, causing the
wait never to return until timeout.

This CL guards updating mStopRequested with lock to make sure that it
must not change between our check and the wait.

After the fix we see no more flaky tests and decreased test execution
time since we will not wait for the next event to come before we end
the timer.

Test: atest android.hardware.automotive.vehicle@2.0-default-impl-unit-tests
Bug: 311757267
Change-Id: Iab1d72b954b4b02aa68e6fbbabcb97b572614d35
1 file changed