mirror of
https://gitee.com/openharmony/graphic_graphic_2d
synced 2025-01-10 17:01:50 +00:00
fix vsync dead lock
Change-Id: I306eb2c0c71213100df6faa6edeecdb7dfa1b571 Signed-off-by: lizheng <lizheng2@huawei.com>
This commit is contained in:
parent
dc5d42a5d3
commit
48fb6d2019
@ -31,7 +31,7 @@ VsyncCallbackProxy::VsyncCallbackProxy(const sptr<IRemoteObject>& impl)
|
|||||||
|
|
||||||
GSError VsyncCallbackProxy::OnVsync(int64_t timestamp)
|
GSError VsyncCallbackProxy::OnVsync(int64_t timestamp)
|
||||||
{
|
{
|
||||||
MessageOption opt;
|
MessageOption opt(MessageOption::TF_ASYNC);
|
||||||
MessageParcel arg;
|
MessageParcel arg;
|
||||||
MessageParcel ret;
|
MessageParcel ret;
|
||||||
|
|
||||||
@ -53,8 +53,7 @@ GSError VsyncCallbackProxy::OnVsync(int64_t timestamp)
|
|||||||
return GSERROR_BINDER;
|
return GSERROR_BINDER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int result = ret.ReadInt32();
|
GSError err = (GSError)ReturnValueTester::Get<int>(GSERROR_OK);
|
||||||
GSError err = (GSError)ReturnValueTester::Get<int>(result);
|
|
||||||
if (err != GSERROR_OK) {
|
if (err != GSERROR_OK) {
|
||||||
VLOG_FAILURE_NO(err);
|
VLOG_FAILURE_NO(err);
|
||||||
return err;
|
return err;
|
||||||
|
@ -60,6 +60,7 @@ GSError VsyncClient::InitService()
|
|||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(serviceMutex_);
|
std::lock_guard<std::mutex> lock(serviceMutex_);
|
||||||
if (service_ == nullptr) {
|
if (service_ == nullptr) {
|
||||||
|
ScopedBytrace func(__func__);
|
||||||
auto sam = StaticCall::GetInstance()->GetSystemAbilityManager();
|
auto sam = StaticCall::GetInstance()->GetSystemAbilityManager();
|
||||||
if (sam == nullptr) {
|
if (sam == nullptr) {
|
||||||
VLOG_FAILURE_RET(GSERROR_CONNOT_CONNECT_SAMGR);
|
VLOG_FAILURE_RET(GSERROR_CONNOT_CONNECT_SAMGR);
|
||||||
@ -146,6 +147,7 @@ GSError VsyncClient::Init(bool restart)
|
|||||||
GSError VsyncClient::InitListener()
|
GSError VsyncClient::InitListener()
|
||||||
{
|
{
|
||||||
while (listener_ == nullptr) {
|
while (listener_ == nullptr) {
|
||||||
|
ScopedBytrace func(__func__);
|
||||||
auto vret = GSERROR_OK;
|
auto vret = GSERROR_OK;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(serviceMutex_);
|
std::lock_guard<std::mutex> lock(serviceMutex_);
|
||||||
@ -211,9 +213,9 @@ GSError VsyncClient::RequestFrameCallback(const struct FrameCallback &cb)
|
|||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lockGuard(callbacksMapMutex_);
|
std::lock_guard<std::mutex> lockGuard(callbacksMapMutex_);
|
||||||
callbacksMap_[vsyncID].push(ele);
|
callbacksMap_[vsyncID].push(ele);
|
||||||
InitListener();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
InitListener();
|
||||||
VLOG_SUCCESS("RequestFrameCallback time: " VPUBI64 ", id: %{public}u", delayTime, vsyncID);
|
VLOG_SUCCESS("RequestFrameCallback time: " VPUBI64 ", id: %{public}u", delayTime, vsyncID);
|
||||||
return GSERROR_OK;
|
return GSERROR_OK;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
#include "vsync_manager.h"
|
#include "vsync_manager.h"
|
||||||
|
|
||||||
|
#include <scoped_bytrace.h>
|
||||||
|
|
||||||
#include "vsync_callback_death_recipient.h"
|
#include "vsync_callback_death_recipient.h"
|
||||||
#include "vsync_callback_proxy.h"
|
#include "vsync_callback_proxy.h"
|
||||||
#include "vsync_log.h"
|
#include "vsync_log.h"
|
||||||
@ -94,6 +96,7 @@ GSError VsyncManager::ListenVsync(sptr<IVsyncCallback>& cb)
|
|||||||
VLOGW("Failed to add death recipient");
|
VLOGW("Failed to add death recipient");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScopedBytrace bytrace(__func__);
|
||||||
std::lock_guard<std::mutex> lock(callbacksMutex_);
|
std::lock_guard<std::mutex> lock(callbacksMutex_);
|
||||||
callbacks_.push_back(cb);
|
callbacks_.push_back(cb);
|
||||||
return GSERROR_OK;
|
return GSERROR_OK;
|
||||||
@ -101,6 +104,8 @@ GSError VsyncManager::ListenVsync(sptr<IVsyncCallback>& cb)
|
|||||||
|
|
||||||
GSError VsyncManager::RemoveVsync(sptr<IVsyncCallback>& callback)
|
GSError VsyncManager::RemoveVsync(sptr<IVsyncCallback>& callback)
|
||||||
{
|
{
|
||||||
|
ScopedBytrace bytrace(__func__);
|
||||||
|
std::lock_guard<std::mutex> lock(callbacksMutex_);
|
||||||
for (auto it = callbacks_.begin(); it != callbacks_.end(); it++) {
|
for (auto it = callbacks_.begin(); it != callbacks_.end(); it++) {
|
||||||
if (*it == callback) {
|
if (*it == callback) {
|
||||||
callbacks_.erase(it);
|
callbacks_.erase(it);
|
||||||
@ -120,16 +125,28 @@ GSError VsyncManager::GetVsyncFrequency(uint32_t &freq)
|
|||||||
|
|
||||||
void VsyncManager::Callback(int64_t timestamp)
|
void VsyncManager::Callback(int64_t timestamp)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(callbacksMutex_);
|
|
||||||
|
|
||||||
using sptrIVsyncCallback = sptr<IVsyncCallback>;
|
using sptrIVsyncCallback = sptr<IVsyncCallback>;
|
||||||
std::list<sptrIVsyncCallback> okcbs;
|
std::list<sptrIVsyncCallback> okcbs, calling;
|
||||||
for (const auto &cb : callbacks_) {
|
{
|
||||||
|
ScopedBytrace bytrace("callback 1");
|
||||||
|
std::lock_guard<std::mutex> lock(callbacksMutex_);
|
||||||
|
calling = callbacks_;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ScopedBytrace bytrace("callback 2");
|
||||||
|
for (const auto &cb : calling) {
|
||||||
if (cb->OnVsync(timestamp) != GSERROR_BINDER) {
|
if (cb->OnVsync(timestamp) != GSERROR_BINDER) {
|
||||||
okcbs.push_back(cb);
|
okcbs.push_back(cb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ScopedBytrace bytrace("callback 3");
|
||||||
|
std::lock_guard<std::mutex> lock(callbacksMutex_);
|
||||||
callbacks_ = okcbs;
|
callbacks_ = okcbs;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} // namespace Vsync
|
} // namespace Vsync
|
||||||
} // namespace OHOS
|
} // namespace OHOS
|
||||||
|
Loading…
Reference in New Issue
Block a user