diff options
| author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-06-28 22:08:45 +0000 |
|---|---|---|
| committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-06-28 22:08:45 +0000 |
| commit | abc846986652f45777f79d7da1046934028b5d2c (patch) | |
| tree | 29b9c195b317b368719db4060bee89dfa863e98d | |
| parent | 525c93b75c754d51e9856d1ccf46a92565ffb7b1 (diff) | |
| parent | 51acf9c5b9c04e6317107eead42e4fd0f35e1798 (diff) | |
| download | platform_hardware_google_camera-simpleperf-release.tar.gz platform_hardware_google_camera-simpleperf-release.tar.bz2 platform_hardware_google_camera-simpleperf-release.zip | |
Snap for 7502275 from 51acf9c5b9c04e6317107eead42e4fd0f35e1798 to simpleperf-releasesimpleperf-release
Change-Id: Idd2365a2f1a31471bc5414953c6b94a3416837c2
| -rw-r--r-- | common/hal/hidl_service/hidl_profiler.cc | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/common/hal/hidl_service/hidl_profiler.cc b/common/hal/hidl_service/hidl_profiler.cc index 3c7e40d..e7e9ab9 100644 --- a/common/hal/hidl_service/hidl_profiler.cc +++ b/common/hal/hidl_service/hidl_profiler.cc @@ -17,6 +17,7 @@ //#define LOG_NDEBUG 0 #define LOG_TAG "GCH_HidlProfiler" #include <log/log.h> +#include <mutex> #include <utility> #include "hidl_profiler.h" @@ -57,6 +58,8 @@ struct HidlProfiler { }; std::unique_ptr<HidlProfiler> gHidlProfiler = nullptr; +// Mutex to make all API functions mutually exclusive. +std::mutex api_mutex; void StartNewConnector() { if (gHidlProfiler != nullptr && gHidlProfiler->profiler != nullptr) { @@ -80,6 +83,7 @@ void EndProfiler() { } // anonymous namespace std::unique_ptr<HidlProfilerItem> OnCameraOpen() { + std::lock_guard lock(api_mutex); gHidlProfiler = std::make_unique<HidlProfiler>(); if (gHidlProfiler == nullptr || gHidlProfiler->profiler == nullptr) { ALOGE("%s: gHidlProfiler or profiler is nullptr.", __FUNCTION__); @@ -94,6 +98,7 @@ std::unique_ptr<HidlProfilerItem> OnCameraOpen() { } std::unique_ptr<HidlProfilerItem> OnCameraFlush() { + std::lock_guard lock(api_mutex); EndConnector(); if (gHidlProfiler == nullptr) { gHidlProfiler = std::make_unique<HidlProfiler>(); @@ -110,6 +115,7 @@ std::unique_ptr<HidlProfilerItem> OnCameraFlush() { } std::unique_ptr<HidlProfilerItem> OnCameraClose() { + std::lock_guard lock(api_mutex); EndConnector(); if (gHidlProfiler == nullptr) { gHidlProfiler = std::make_unique<HidlProfiler>(); @@ -126,6 +132,7 @@ std::unique_ptr<HidlProfilerItem> OnCameraClose() { } std::unique_ptr<HidlProfilerItem> OnCameraStreamConfigure() { + std::lock_guard lock(api_mutex); EndConnector(); if (gHidlProfiler == nullptr) { gHidlProfiler = std::make_unique<HidlProfiler>(); @@ -146,6 +153,7 @@ std::unique_ptr<HidlProfilerItem> OnCameraStreamConfigure() { } void OnFirstFrameRequest() { + std::lock_guard lock(api_mutex); EndConnector(); if (gHidlProfiler != nullptr && gHidlProfiler->profiler != nullptr) { gHidlProfiler->profiler->Start( @@ -156,6 +164,7 @@ void OnFirstFrameRequest() { } void OnFirstFrameResult() { + std::lock_guard lock(api_mutex); if (gHidlProfiler != nullptr && gHidlProfiler->profiler != nullptr) { gHidlProfiler->profiler->End( "First frame", google::camera_common::Profiler::kInvalidRequestId); |
