diff options
| author | 2020-07-21 15:42:55 +0800 | |
|---|---|---|
| committer | 2020-09-15 09:48:33 +0000 | |
| commit | bf63d8a54e4b8dbcb26fe55b50c64223a232c511 (patch) | |
| tree | 8b4c00e4a4d63c8fd6ec27886f653e997fa839ac | |
| parent | 3c2fdbd82090e0c1c3996c5f5091df309592699c (diff) | |
Faster bugreports (4/n)
Makes update progress thread safe.
Bug: 136262402
Test: atest dumpstate_test
Test: atest dumpstate_smoke_test
Change-Id: I1cb593d236b86122d19a5a6c11496a449e519d03
| -rw-r--r-- | cmds/dumpstate/dumpstate.cpp | 6 | ||||
| -rw-r--r-- | cmds/dumpstate/dumpstate.h | 2 |
2 files changed, 7 insertions, 1 deletions
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<std::recursive_mutex> 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<ConsentCallback> consent_callback_; + std::recursive_mutex mutex_; + DISALLOW_COPY_AND_ASSIGN(Dumpstate); }; |