mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-24 01:09:51 +00:00
resolve p2p entity deadlock and crash
Signed-off-by: lee-wen-qiang <liwenqiang45@huawei.com>
This commit is contained in:
parent
b189f0f074
commit
76c2e6d9ca
@ -127,7 +127,14 @@ void P2pConnectState::PreprocessP2pConnectionChangeEvent(
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "group info is null, skip config ip");
|
||||
return;
|
||||
}
|
||||
P2pEntity::GetInstance().Lock();
|
||||
if (operation_ == nullptr) {
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "operation is null");
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
return;
|
||||
}
|
||||
auto operation = std::dynamic_pointer_cast<P2pOperationWrapper<P2pConnectParam>>(operation_);
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
if (operation->content_.isNeedDhcp) {
|
||||
std::string localIpStr;
|
||||
if (P2pAdapter::GetIpAddress(localIpStr) == SOFTBUS_OK) {
|
||||
@ -145,10 +152,12 @@ void P2pConnectState::PreprocessP2pConnectionChangeEvent(
|
||||
void P2pConnectState::OnP2pConnectionChangeEvent(
|
||||
const WifiP2pLinkedInfo &info, const std::shared_ptr<P2pAdapter::WifiDirectP2pGroupInfo> &groupInfo)
|
||||
{
|
||||
P2pEntity::GetInstance().Lock();
|
||||
P2pAdapter::WifiDirectP2pGroupInfo ignore {};
|
||||
auto ret = P2pAdapter::GetGroupInfo(ignore);
|
||||
if (operation_ == nullptr) {
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "operation is null");
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
return;
|
||||
}
|
||||
timer_.Unregister(operation_->timerId_);
|
||||
@ -162,17 +171,21 @@ void P2pConnectState::OnP2pConnectionChangeEvent(
|
||||
ChangeState(P2pAvailableState::Instance(), nullptr);
|
||||
operation_->promise_.set_value(result);
|
||||
operation_ = nullptr;
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
}
|
||||
|
||||
void P2pConnectState::OnTimeout()
|
||||
{
|
||||
P2pEntity::GetInstance().Lock();
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "timeout");
|
||||
if (operation_ == nullptr) {
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "operation is nullptr");
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
return;
|
||||
}
|
||||
ChangeState(P2pAvailableState::Instance(), nullptr);
|
||||
operation_->promise_.set_value(P2pOperationResult(static_cast<int>(SOFTBUS_CONN_CONNECT_GROUP_TIMEOUT)));
|
||||
operation_ = nullptr;
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
}
|
||||
} // namespace OHOS::SoftBus
|
@ -91,8 +91,10 @@ void P2pCreateGroupState::OnP2pStateChangeEvent(P2pState state)
|
||||
void P2pCreateGroupState::OnP2pConnectionChangeEvent(
|
||||
const WifiP2pLinkedInfo &info, const std::shared_ptr<P2pAdapter::WifiDirectP2pGroupInfo> &groupInfo)
|
||||
{
|
||||
P2pEntity::GetInstance().Lock();
|
||||
if (operation_ == nullptr) {
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "operation is null");
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
return;
|
||||
}
|
||||
timer_.Unregister(operation_->timerId_);
|
||||
@ -107,17 +109,21 @@ void P2pCreateGroupState::OnP2pConnectionChangeEvent(
|
||||
ChangeState(P2pAvailableState::Instance(), nullptr);
|
||||
operation_->promise_.set_value(result);
|
||||
operation_ = nullptr;
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
}
|
||||
|
||||
void P2pCreateGroupState::OnTimeout()
|
||||
{
|
||||
P2pEntity::GetInstance().Lock();
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "timeout");
|
||||
if (operation_ == nullptr) {
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "operation is nullptr");
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
return;
|
||||
}
|
||||
ChangeState(P2pAvailableState::Instance(), nullptr);
|
||||
operation_->promise_.set_value(P2pOperationResult(static_cast<int>(SOFTBUS_CONN_CREATE_GROUP_TIMEOUT)));
|
||||
operation_ = nullptr;
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
}
|
||||
} // namespace OHOS::SoftBus
|
@ -90,9 +90,11 @@ void P2pDestroyGroupState::OnP2pStateChangeEvent(P2pState state)
|
||||
void P2pDestroyGroupState::OnP2pConnectionChangeEvent(
|
||||
const WifiP2pLinkedInfo &info, const std::shared_ptr<P2pAdapter::WifiDirectP2pGroupInfo> &groupInfo)
|
||||
{
|
||||
P2pEntity::GetInstance().Lock();
|
||||
CONN_LOGI(CONN_WIFI_DIRECT, "enter");
|
||||
if (operation_ == nullptr) {
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "operation is null");
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
return;
|
||||
}
|
||||
timer_.Unregister(operation_->timerId_);
|
||||
@ -107,18 +109,22 @@ void P2pDestroyGroupState::OnP2pConnectionChangeEvent(
|
||||
ChangeState(P2pAvailableState::Instance(), nullptr);
|
||||
operation_->promise_.set_value(result);
|
||||
operation_ = nullptr;
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
}
|
||||
|
||||
void P2pDestroyGroupState::OnTimeout()
|
||||
{
|
||||
P2pEntity::GetInstance().Lock();
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "timeout");
|
||||
P2pEntity::GetInstance().currentFrequency_ = 0;
|
||||
if (operation_ == nullptr) {
|
||||
CONN_LOGE(CONN_WIFI_DIRECT, "operation is nullptr");
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
return;
|
||||
}
|
||||
ChangeState(P2pAvailableState::Instance(), nullptr);
|
||||
operation_->promise_.set_value(P2pOperationResult(static_cast<int>(SOFTBUS_CONN_DESTROY_GROUP_TIMEOUT)));
|
||||
operation_ = nullptr;
|
||||
P2pEntity::GetInstance().Unlock();
|
||||
}
|
||||
} // namespace OHOS::SoftBus
|
@ -21,6 +21,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "conn_log.h"
|
||||
#include "kits/c/wifi_p2p.h"
|
||||
|
||||
#include "adapter/p2p_adapter.h"
|
||||
@ -89,6 +90,17 @@ public:
|
||||
void UpdateInterfaceManagerWhenStateChanged(P2pState state);
|
||||
static void Listener(BroadcastReceiverAction action, const struct BroadcastParam ¶m);
|
||||
|
||||
void Lock()
|
||||
{
|
||||
CONN_LOGD(CONN_WIFI_DIRECT, "lock");
|
||||
operationLock_.lock();
|
||||
}
|
||||
void Unlock()
|
||||
{
|
||||
CONN_LOGD(CONN_WIFI_DIRECT, "unlock");
|
||||
operationLock_.unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
P2pEntity();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user