diff --git a/app/src/semaphore.h b/app/src/semaphore.h index 23a77305e9..316373d8a0 100644 --- a/app/src/semaphore.h +++ b/app/src/semaphore.h @@ -172,7 +172,30 @@ class Semaphore { return WaitForSingleObject(semaphore_, milliseconds) == 0; #else // not windows and not mac - should be Linux. timespec t = internal::MsToAbsoluteTimespec(milliseconds); - return sem_timedwait(semaphore_, &t) == 0; + while (true) { + int result = sem_timedwait(semaphore_, &t); + if (result == 0) { + // Return success, since we successfully locked the semaphore. + return true; + } + switch (errno) { + case EINTR: + // Restart the wait because we were woken up spuriously. + continue; + case ETIMEDOUT: + // Return failure, since the timeout expired. + return false; + case EINVAL: + assert("sem_timedwait() failed with EINVAL" == 0); + return false; + case EDEADLK: + assert("sem_timedwait() failed with EDEADLK" == 0); + return false; + default: + assert("sem_timedwait() failed with an unknown error" == 0); + return false; + } + } #endif } diff --git a/release_build_files/readme.md b/release_build_files/readme.md index a746e46a2f..380f543d1d 100644 --- a/release_build_files/readme.md +++ b/release_build_files/readme.md @@ -634,6 +634,13 @@ workflow use only during the development of your app, not for publicly shipping code. ## Release Notes +### Upcoming Changes +- Changes + - General (Android,Linux): Fixed a concurrency bug where waiting for an + event with a timeout could occasionally return prematurely, as if the + timeout had occurred + ([#1021](https://github.com/firebase/firebase-cpp-sdk/pull/1021)). + ### 9.2.0 - Changes - GMA: Added the Google Mobile Ads SDK with updated support for AdMob. See