Merge "Update to handle spurious wake up in conditional variable"

This commit is contained in:
TreeHugger Robot
2023-03-03 07:50:27 +00:00
committed by Android (Google) Code Review

View File

@@ -44,6 +44,12 @@ using video_widevine::ProvisioningResponse;
using wvcdm::kLevel3;
using wvcdm::kLevelDefault;
using namespace std;
using namespace std::chrono;
#define GET_TIME() \
((duration_cast<milliseconds>(system_clock::now().time_since_epoch())) \
.count())
#define TIMEOUT_IN_MILLISECONDS 2 * 60 * 1000 // 2 minutes
namespace {
@@ -532,7 +538,16 @@ class WatchDog {
{
std::unique_lock<std::mutex> lock(mutex_);
if (running_) {
condition_.wait_for(lock, std::chrono::minutes(2));
bool waitStatus = false;
time_t time = GET_TIME();
do {
waitStatus = condition_.wait_for(
lock, std::chrono::milliseconds(TIMEOUT_IN_MILLISECONDS),
[time, this]() {
return ((GET_TIME() > time + TIMEOUT_IN_MILLISECONDS) |
(!running_));
});
} while (waitStatus != true);
}
if (running_) {
gave_up_ = true;