Faster bugreports (4/n)

Makes update progress thread safe.

Bug: 136262402
Test: atest dumpstate_test
Test: atest dumpstate_smoke_test
Change-Id: I1cb593d236b86122d19a5a6c11496a449e519d03
Merged-In: I1cb593d236b86122d19a5a6c11496a449e519d03
(cherry picked from commit bf63d8a54e4b8dbcb26fe55b50c64223a232c511)
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index b9dfbe0..e8996d2 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -3881,12 +3881,16 @@
     fclose(fp);
 }
 
-// TODO: make this function thread safe if sections are generated in parallel.
 void Dumpstate::UpdateProgress(int32_t delta_sec) {
     if (progress_ == nullptr) {
         MYLOGE("UpdateProgress: progress_ not set\n");
         return;
     }
+    // This function updates progress related members of the dumpstate and reports
+    // progress percentage to the bugreport client. Since it could be called by
+    // different dump tasks at the same time if the parallel run is enabled, a
+    // mutex lock is necessary here to synchronize the call.
+    std::lock_guard<std::recursive_mutex> lock(mutex_);
 
     // Always update progess so stats can be tuned...
     progress_->Inc(delta_sec);