已合并
std::recursive_mutex -> ffrt::recursive_mutex #18901
wangdi创建于 4月27日
std::recursive_mutex -> ffrt::recursive_mutex #18901
已合并
共 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 | 20 | ||
| 21 | 21 | ||
| 22 | 22 | ||
| 23 | - | ||
| 24 | namespace OHOS { | 23 | namespace OHOS { |
| 25 | namespace Rosen { | 24 | namespace Rosen { |
| 26 | class TaskSequenceProcess; | 25 | class TaskSequenceProcess; |
| @@ -45,6 +44,7 @@ public: | |||
| 45 | 44 | ||
| 46 | protected: | 45 | protected: |
| 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; |
| 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 | 29 | ||
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | + | ||
| 32 | 33 | ||
| 33 | namespace OHOS::Rosen::DMS { | 34 | namespace OHOS::Rosen::DMS { |
| 34 | 35 | ||
| @@ -49,6 +50,11 @@ constexpr uint64_t MAX_TIME_INTERVAL_MS = 2000; | |||
| 49 | std::chrono::time_point<std::chrono::system_clock> g_lastUpdateTime = std::chrono::system_clock::now(); | 50 | std::chrono::time_point<std::chrono::system_clock> g_lastUpdateTime = std::chrono::system_clock::now(); |
| 50 | } // namespace | 51 | } // namespace |
| 51 | 52 | ||
| 53 | +class SensorFoldStateMgr::Impl { | ||
| 54 | +public: | ||
| 55 | + ffrt::recursive_mutex statusMutex_; | ||
| 56 | +}; | ||
| 57 | + | ||
| 52 | SensorFoldStateMgr& SensorFoldStateMgr::GetInstance() | 58 | SensorFoldStateMgr& 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 | + | ||
| 80 | void SensorFoldStateMgr::SetTaskScheduler(std::shared_ptr<TaskScheduler> scheduler) | 88 | void 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 | ||
| 217 | void SensorFoldStateMgr::HandleSensorChange(FoldStatus nextStatus) | 225 | void 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 | 25 | ||
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | - | 28 | +#include "ffrt.h" |
| 29 | namespace OHOS::Rosen { | 29 | namespace OHOS::Rosen { |
| 30 | namespace { | 30 | namespace { |
| 31 | constexpr int32_t MAX_QUEUE_SIZE = 1; | 31 | constexpr int32_t MAX_QUEUE_SIZE = 1; |
| 32 | constexpr uint64_t MAX_TIME_INTERVAL_MS = 2000; | 32 | constexpr 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); |
单例类,可以仅在cpp中定义Impl