已合并
std::recursive_mutex -> ffrt::recursive_mutex #18901
std::recursive_mutex -> ffrt::recursive_mutex #18901
已合并
wangdi创建于 4月27日
共 4 个文件变更+27-11
@@ -53,7 +53,8 @@ protected:
53 const std::vector<uint16_t>& halls, sptr<FoldScreenPolicy> foldScreenPolicy);53 const std::vector<uint16_t>& halls, sptr<FoldScreenPolicy> foldScreenPolicy);
54 FoldStatus GetCurrentState();54 FoldStatus GetCurrentState();
55 void SetTentMode(int tentType);55 void SetTentMode(int tentType);
56- std::recursive_mutex mStateMutex_;56+ class Impl;
57+ std::unique_ptr<Impl> pImpl_;
57 int tentModeType_ = 0;58 int tentModeType_ = 0;
58 inline static bool isInOneStep_ = false;59 inline static bool isInOneStep_ = false;
59 inline static std::condition_variable oneStep_;60 inline static std::condition_variable oneStep_;
@@ -20,7 +20,6 @@
20#include "iapplication_state_observer.h"20#include "iapplication_state_observer.h"
21#include "fold_screen_common.h"21#include "fold_screen_common.h"
22#include "task_scheduler.h"22#include "task_scheduler.h"
23- 
24namespace OHOS {23namespace OHOS {
25namespace Rosen {24namespace Rosen {
26class TaskSequenceProcess;25class TaskSequenceProcess;
@@ -45,6 +44,7 @@ public:
45 44 
46protected:45protected:
47 SensorFoldStateMgr();46 SensorFoldStateMgr();
47+ virtual ~SensorFoldStateMgr();
48 FoldStatus GetNextFoldStatus(const SensorStatus& sensorStatus);48 FoldStatus GetNextFoldStatus(const SensorStatus& sensorStatus);
49 virtual FoldStatus GetNextFoldStatusByAxis(49 virtual FoldStatus GetNextFoldStatusByAxis(
50 const ScreenAxis& axis, FoldStatus currentStatus, int32_t algorithmStrategy);50 const ScreenAxis& axis, FoldStatus currentStatus, int32_t algorithmStrategy);
@@ -74,7 +74,8 @@ private:
74 void SetDeviceStatusAndParam(uint32_t deviceStatus);74 void SetDeviceStatusAndParam(uint32_t deviceStatus);
75 75 
76 std::vector<int32_t> foldAlgorithmStrategy_;76 std::vector<int32_t> foldAlgorithmStrategy_;
77- std::recursive_mutex statusMutex_;77+ class Impl;
wulong158
wulong158wulong1584月30日

单例类,可以仅在cpp中定义Impl

likedislike
78+ std::unique_ptr<Impl> pImpl_;
78 FoldStatus globalFoldStatus_ = FoldStatus::UNKNOWN;79 FoldStatus globalFoldStatus_ = FoldStatus::UNKNOWN;
79 TaskSequenceProcess* taskProcess_;80 TaskSequenceProcess* taskProcess_;
80};81};
@@ -29,6 +29,7 @@
29#ifdef POWER_MANAGER_ENABLE29#ifdef POWER_MANAGER_ENABLE
30#include <power_mgr_client.h>30#include <power_mgr_client.h>
31#endif31#endif
32+#include "ffrt.h"
32 33 
33namespace OHOS::Rosen::DMS {34namespace OHOS::Rosen::DMS {
34 35 
@@ -49,6 +50,11 @@ constexpr uint64_t MAX_TIME_INTERVAL_MS = 2000;
49std::chrono::time_point<std::chrono::system_clock> g_lastUpdateTime = std::chrono::system_clock::now();50std::chrono::time_point<std::chrono::system_clock> g_lastUpdateTime = std::chrono::system_clock::now();
50} // namespace51} // namespace
51 52 
53+class SensorFoldStateMgr::Impl {
54+public:
55+ ffrt::recursive_mutex statusMutex_;
56+};
57+ 
52SensorFoldStateMgr& SensorFoldStateMgr::GetInstance()58SensorFoldStateMgr& SensorFoldStateMgr::GetInstance()
53{59{
54 static std::mutex singletonMutex_;60 static std::mutex singletonMutex_;
@@ -67,7 +73,7 @@ SensorFoldStateMgr& SensorFoldStateMgr::GetInstance()
67 return *instance_;73 return *instance_;
68}74}
69 75 
70-SensorFoldStateMgr::SensorFoldStateMgr()76+SensorFoldStateMgr::SensorFoldStateMgr() : pImpl_(std::make_unique<Impl>())
71{77{
72 taskProcess_ = new TaskSequenceProcess(78 taskProcess_ = new TaskSequenceProcess(
73 MAX_QUEUE_SIZE,79 MAX_QUEUE_SIZE,
@@ -77,6 +83,8 @@ SensorFoldStateMgr::SensorFoldStateMgr()
77 foldAlgorithmStrategy_ = {0, 0};83 foldAlgorithmStrategy_ = {0, 0};
78}84}
79 85 
86+SensorFoldStateMgr::~SensorFoldStateMgr() = default;
87+ 
80void SensorFoldStateMgr::SetTaskScheduler(std::shared_ptr<TaskScheduler> scheduler)88void SensorFoldStateMgr::SetTaskScheduler(std::shared_ptr<TaskScheduler> scheduler)
81{89{
82 if (scheduler == nullptr) {90 if (scheduler == nullptr) {
@@ -216,7 +224,7 @@ std::vector<std::string> SensorFoldStateMgr::getHallSwitchAppList()
216 224 
217void SensorFoldStateMgr::HandleSensorChange(FoldStatus nextStatus)225void SensorFoldStateMgr::HandleSensorChange(FoldStatus nextStatus)
218{226{
219- std::lock_guard<std::recursive_mutex> lock(statusMutex_);227+ std::lock_guard<ffrt::recursive_mutex> lock(pImpl_->statusMutex_);
220 if (nextStatus == FoldStatus::UNKNOWN) {228 if (nextStatus == FoldStatus::UNKNOWN) {
221 TLOGW(WmsLogTag::DMS, "fold state is UNKNOWN");229 TLOGW(WmsLogTag::DMS, "fold state is UNKNOWN");
222 return;230 return;
@@ -25,13 +25,19 @@
25#ifdef POWER_MANAGER_ENABLE25#ifdef POWER_MANAGER_ENABLE
26#include <power_mgr_client.h>26#include <power_mgr_client.h>
27#endif27#endif
28- 28+#include "ffrt.h"
29namespace OHOS::Rosen {29namespace OHOS::Rosen {
30namespace {30namespace {
31constexpr int32_t MAX_QUEUE_SIZE = 1;31constexpr int32_t MAX_QUEUE_SIZE = 1;
32constexpr uint64_t MAX_TIME_INTERVAL_MS = 2000;32constexpr uint64_t MAX_TIME_INTERVAL_MS = 2000;
33}33}
34-SensorFoldStateManager::SensorFoldStateManager()34+ 
35+class SensorFoldStateManager::Impl {
36+public:
37+ ffrt::recursive_mutex mStateMutex_;
38+};
39+ 
40+SensorFoldStateManager::SensorFoldStateManager() : pImpl_(std::make_unique<Impl>())
35{41{
36 taskProcess_ = new TaskSequenceProcess(42 taskProcess_ = new TaskSequenceProcess(
37 MAX_QUEUE_SIZE,43 MAX_QUEUE_SIZE,
@@ -74,7 +80,7 @@ void SensorFoldStateManager::HandleSensorChange(FoldStatus nextState, float angl
74 return;80 return;
75 }81 }
76 auto task = [=] {82 auto task = [=] {
77- std::lock_guard<std::recursive_mutex> lock(mStateMutex_);83+ std::lock_guard<ffrt::recursive_mutex> lock(pImpl_->mStateMutex_);
78 if (mState_ != nextState) {84 if (mState_ != nextState) {
79 TLOGI(WmsLogTag::DMS, "current state: %{public}d, next state: %{public}d.", mState_, nextState);85 TLOGI(WmsLogTag::DMS, "current state: %{public}d, next state: %{public}d.", mState_, nextState);
80 ReportNotifyFoldStatusChange(static_cast<int32_t>(mState_), static_cast<int32_t>(nextState), angle);86 ReportNotifyFoldStatusChange(static_cast<int32_t>(mState_), static_cast<int32_t>(nextState), angle);
@@ -110,7 +116,7 @@ void SensorFoldStateManager::HandleSensorChange(FoldStatus nextState, const std:
110 const std::vector<uint16_t>& halls, sptr<FoldScreenPolicy> foldScreenPolicy)116 const std::vector<uint16_t>& halls, sptr<FoldScreenPolicy> foldScreenPolicy)
111{117{
112 {118 {
113- std::lock_guard<std::recursive_mutex> lock(mStateMutex_);119+ std::lock_guard<ffrt::recursive_mutex> lock(pImpl_->mStateMutex_);
114 if (nextState == FoldStatus::UNKNOWN) {120 if (nextState == FoldStatus::UNKNOWN) {
115 TLOGW(WmsLogTag::DMS, "fold state is UNKNOWN");121 TLOGW(WmsLogTag::DMS, "fold state is UNKNOWN");
116 return;122 return;
@@ -145,13 +151,13 @@ void SensorFoldStateManager::HandleSensorChange(FoldStatus nextState, const std:
145 FoldStatus currentState = FoldStatus::UNKNOWN;151 FoldStatus currentState = FoldStatus::UNKNOWN;
146 FoldStatus newState = FoldStatus::UNKNOWN;152 FoldStatus newState = FoldStatus::UNKNOWN;
147 {153 {
148- std::lock_guard<std::recursive_mutex> lock(manager->mStateMutex_);154+ std::lock_guard<ffrt::recursive_mutex> lock(manager->pImpl_->mStateMutex_);
149 currentState = manager->mState_;155 currentState = manager->mState_;
150 }156 }
151 TLOGNI(WmsLogTag::DMS, "current state: %{public}d, next state: %{public}d.", currentState, nextState);157 TLOGNI(WmsLogTag::DMS, "current state: %{public}d, next state: %{public}d.", currentState, nextState);
152 newState = manager->HandleSecondaryOneStep(currentState, nextState, angles, halls);158 newState = manager->HandleSecondaryOneStep(currentState, nextState, angles, halls);
153 {159 {
154- std::lock_guard<std::recursive_mutex> lock(manager->mStateMutex_);160+ std::lock_guard<ffrt::recursive_mutex> lock(manager->pImpl_->mStateMutex_);
155 manager->mState_ = newState;161 manager->mState_ = newState;
156 }162 }
157 manager->ProcessNotifyFoldStatusChange(currentState, newState, angles, policy);163 manager->ProcessNotifyFoldStatusChange(currentState, newState, angles, policy);