From bf63d8a54e4b8dbcb26fe55b50c64223a232c511 Mon Sep 17 00:00:00 2001 From: Rhed Jao Date: Tue, 21 Jul 2020 15:42:55 +0800 Subject: Faster bugreports (4/n) Makes update progress thread safe. Bug: 136262402 Test: atest dumpstate_test Test: atest dumpstate_smoke_test Change-Id: I1cb593d236b86122d19a5a6c11496a449e519d03 --- cmds/dumpstate/dumpstate.cpp | 6 +++++- cmds/dumpstate/dumpstate.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'cmds') diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index e267ce336b..d7700acbc2 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -3880,12 +3880,16 @@ void dump_route_tables() { 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 lock(mutex_); // Always update progess so stats can be tuned... progress_->Inc(delta_sec); diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h index 0f0927cc29..75b3140b27 100644 --- a/cmds/dumpstate/dumpstate.h +++ b/cmds/dumpstate/dumpstate.h @@ -572,6 +572,8 @@ class Dumpstate { android::sp consent_callback_; + std::recursive_mutex mutex_; + DISALLOW_COPY_AND_ASSIGN(Dumpstate); }; -- cgit v1.2.3-59-g8ed1b