增加同步超时兜底

Signed-off-by: yanghua_angel <yanghua58@huawei.com>
This commit is contained in:
yanghua_angel 2024-11-21 19:44:13 +08:00
parent b0cdcb846d
commit 57692eb683
7 changed files with 61 additions and 13 deletions

View File

@ -1330,7 +1330,7 @@ void RSMainThread::ProcessSyncTransactionCount(std::unique_ptr<RSTransactionData
subSyncTransactionCounts_.erase(parentPid);
}
}
ROSEN_LOGD("RSMainThread::ProcessSyncTransactionCount isNeedCloseSync:%{public}d syncId:%{public}" PRIu64 ""
ROSEN_LOGI("RSMainThread::ProcessSyncTransactionCount isNeedCloseSync:%{public}d syncId:%{public}" PRIu64 ""
" parentPid:%{public}d syncNum:%{public}d subSyncTransactionCounts_.size:%{public}zd",
rsTransactionData->IsNeedCloseSync(), rsTransactionData->GetSyncId(), parentPid,
rsTransactionData->GetSyncTransactionNum(), subSyncTransactionCounts_.size());
@ -1364,7 +1364,7 @@ void RSMainThread::ProcessSyncRSTransactionData(std::unique_ptr<RSTransactionDat
ProcessSyncTransactionCount(rsTransactionData);
syncTransactionData_[pid].emplace_back(std::move(rsTransactionData));
if (subSyncTransactionCounts_.empty()) {
ROSEN_LOGD("SyncTransaction sucess");
ROSEN_LOGI("SyncTransaction success");
ProcessAllSyncTransactionData();
}
}

View File

@ -18,6 +18,7 @@
#include <memory>
#include <mutex>
#include <queue>
#include <stack>
#include "command/rs_command.h"
@ -72,6 +73,8 @@ public:
bool IsEmpty() const;
void StartCloseSyncTransactionFallbackTask(std::shared_ptr<AppExecFwk::EventHandler> handler, bool isOpen);
private:
RSTransactionProxy();
virtual ~RSTransactionProxy();
@ -107,6 +110,7 @@ private:
uint64_t syncId_ { 0 };
FlushEmptyCallback flushEmptyCallback_ = nullptr;
uint32_t transactionDataIndex_ = 0;
std::queue<std::string> taskNames_ {};
};
} // namespace Rosen
} // namespace OHOS

View File

@ -17,6 +17,7 @@
#include <stdlib.h>
#include "platform/common/rs_log.h"
#include "rs_trace.h"
namespace OHOS {
namespace Rosen {
@ -193,6 +194,42 @@ void RSTransactionProxy::CloseSyncTransaction()
needSync_ = false;
}
void RSTransactionProxy::StartCloseSyncTransactionFallbackTask(
std::shared_ptr<AppExecFwk::EventHandler> handler, bool isOpen)
{
std::unique_lock<std::mutex> cmdLock(mutex_);
static uint32_t num = 0;
const std::string name = "CloseSyncTransactionFallbackTask";
const int timeOutDelay = 5000;
if (!handler) {
ROSEN_LOGD("StartCloseSyncTransactionFallbackTask handler is null");
return;
}
if (isOpen) {
num++;
auto taskName = name + std::to_string(num);
taskNames_.push(taskName);
auto task = [this]() {
RS_TRACE_NAME("CloseSyncTransaction timeout");
ROSEN_LOGE("CloseSyncTransaction timeout");
auto transactionProxy = RSTransactionProxy::GetInstance();
if (transactionProxy != nullptr) {
transactionProxy->CommitSyncTransaction();
transactionProxy->CloseSyncTransaction();
}
if (!taskNames_.empty()) {
taskNames_.pop();
}
};
handler->PostTask(task, taskName, timeOutDelay);
} else {
if (!taskNames_.empty()) {
handler->RemoveTask(taskNames_.front());
taskNames_.pop();
}
}
}
void RSTransactionProxy::Begin()
{
std::unique_lock<std::mutex> cmdLock(mutex_);

View File

@ -54,7 +54,7 @@ std::shared_ptr<RSTransaction> RSSyncTransactionController::GetRSTransaction()
return rsTransaction_;
}
void RSSyncTransactionController::OpenSyncTransaction()
void RSSyncTransactionController::OpenSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler)
{
if (!RSSystemProperties::GetSyncTransactionEnabled()) {
return;
@ -69,11 +69,11 @@ void RSSyncTransactionController::OpenSyncTransaction()
}
ROSEN_LOGD("RS sync transaction controller OpenSyncTransaction");
if (rsTransaction_) {
rsTransaction_->OpenSyncTransaction();
rsTransaction_->OpenSyncTransaction(handler);
}
}
void RSSyncTransactionController::CloseSyncTransaction()
void RSSyncTransactionController::CloseSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler)
{
if (!needCloseSync_) {
return;
@ -81,7 +81,7 @@ void RSSyncTransactionController::CloseSyncTransaction()
ROSEN_LOGD("RS sync transaction controller CloseSyncTransaction");
if (rsTransaction_) {
rsTransaction_->CloseSyncTransaction();
rsTransaction_->CloseSyncTransaction(handler);
}
{
std::unique_lock<std::mutex> lock(mutex_);

View File

@ -30,8 +30,8 @@ class RSC_EXPORT RSSyncTransactionController {
public:
static RSSyncTransactionController* GetInstance();
void OpenSyncTransaction();
void CloseSyncTransaction();
void OpenSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
void CloseSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
std::shared_ptr<RSTransaction> GetRSTransaction();

View File

@ -31,33 +31,36 @@ void RSTransaction::FlushImplicitTransaction()
}
}
void RSTransaction::OpenSyncTransaction()
void RSTransaction::OpenSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler)
{
syncId_ = GenerateSyncId();
auto transactionProxy = RSTransactionProxy::GetInstance();
if (transactionProxy != nullptr) {
RS_TRACE_NAME("OpenSyncTransaction");
ROSEN_LOGI("OpenSyncTransaction");
transactionProxy->FlushImplicitTransaction();
transactionProxy->StartSyncTransaction();
transactionProxy->Begin();
isOpenSyncTransaction_ = true;
transactionCount_ = 0;
parentPid_ = GetRealPid();
transactionProxy->StartCloseSyncTransactionFallbackTask(handler, true);
}
}
void RSTransaction::CloseSyncTransaction()
void RSTransaction::CloseSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler)
{
auto transactionProxy = RSTransactionProxy::GetInstance();
if (transactionProxy != nullptr) {
RS_TRACE_NAME_FMT("CloseSyncTransaction syncId: %lu syncCount: %d", syncId_, transactionCount_);
ROSEN_LOGD(
ROSEN_LOGI(
"CloseSyncTransaction syncId: %{public}" PRIu64 " syncCount: %{public}d", syncId_, transactionCount_);
isOpenSyncTransaction_ = false;
transactionProxy->MarkTransactionNeedCloseSync(transactionCount_);
transactionProxy->SetSyncId(syncId_);
transactionProxy->CommitSyncTransaction();
transactionProxy->CloseSyncTransaction();
transactionProxy->StartCloseSyncTransactionFallbackTask(handler, false);
}
ResetSyncTransactionInfo();
}
@ -67,6 +70,7 @@ void RSTransaction::Begin()
auto transactionProxy = RSTransactionProxy::GetInstance();
if (transactionProxy != nullptr) {
RS_TRACE_NAME("BeginSyncTransaction");
ROSEN_LOGI("BeginSyncTransaction");
transactionProxy->StartSyncTransaction();
transactionProxy->Begin();
}
@ -78,6 +82,8 @@ void RSTransaction::Commit()
if (transactionProxy != nullptr) {
RS_TRACE_NAME_FMT(
"CommitSyncTransaction syncId: %lu syncCount: %d parentPid: %d", syncId_, transactionCount_, parentPid_);
ROSEN_LOGI("CloseSyncTransaction syncId: %{public}" PRIu64 " syncCount: %{public}d parentPid: %{public}d",
syncId_, transactionCount_, parentPid_);
transactionProxy->SetSyncTransactionNum(transactionCount_);
transactionProxy->SetSyncId(syncId_);
transactionProxy->SetParentPid(parentPid_);

View File

@ -16,6 +16,7 @@
#ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_TRANSACTION_H
#define RENDER_SERVICE_CLIENT_CORE_UI_RS_TRANSACTION_H
#include <event_handler.h>
#include <message_parcel.h>
#include <mutex>
#include <parcel.h>
@ -40,8 +41,8 @@ public:
bool Marshalling(Parcel& parcel) const override;
static void FlushImplicitTransaction();
void OpenSyncTransaction();
void CloseSyncTransaction();
void OpenSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
void CloseSyncTransaction(std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr);
void Begin();
void Commit();