Merge "Fix race condition is commitCheckpoint" am: 1059810759
am: 556bd755e6
Change-Id: Ie80a3c123a5d30915cade7ddc1aad2d790476448
diff --git a/Checkpoint.cpp b/Checkpoint.cpp
index 362c823..a2db4bd 100644
--- a/Checkpoint.cpp
+++ b/Checkpoint.cpp
@@ -144,9 +144,15 @@
namespace {
volatile bool isCheckpointing = false;
+
+// Protects isCheckpointing and code that makes decisions based on status of
+// isCheckpointing
+std::mutex isCheckpointingLock;
}
Status cp_commitChanges() {
+ std::lock_guard<std::mutex> lock(isCheckpointingLock);
+
if (!isCheckpointing) {
return Status::ok();
}
@@ -261,6 +267,7 @@
std::string content;
sp<IBootControl> module = IBootControl::getService();
+ std::lock_guard<std::mutex> lock(isCheckpointingLock);
if (isCheckpointing) return isCheckpointing;
if (module && module->isSlotMarkedSuccessful(module->getCurrentSlot()) == BoolResult::FALSE) {
@@ -330,6 +337,7 @@
} // namespace
Status cp_prepareCheckpoint() {
+ std::lock_guard<std::mutex> lock(isCheckpointingLock);
if (!isCheckpointing) {
return Status::ok();
}