From a1ffc20c85e297e4c69c709aed6ba4bdea21d721 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 7 May 2023 07:57:45 +0000 Subject: [PATCH] 1 --- server/wsproxy/app.cc | 16 ++++------------ server/wsproxy/app.h | 8 ++++---- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/server/wsproxy/app.cc b/server/wsproxy/app.cc index b45c0e0..8b9c3d0 100644 --- a/server/wsproxy/app.cc +++ b/server/wsproxy/app.cc @@ -115,10 +115,10 @@ bool App::Init(int argc, char* argv[]) }); uuid_ = std::make_shared(); - loop_mutex_ = new std::mutex(); - loop_cond_ = new std::condition_variable(); - msg_mutex_ = new std::mutex(); - udp_msg_mutex_ = new std::mutex(); + loop_mutex_ = std::make_shared(); + loop_cond_ = std::make_shared(); + msg_mutex_ = std::make_shared(); + udp_msg_mutex_ = std::make_shared(); srand(time(nullptr)); InitLog(); @@ -197,14 +197,6 @@ void App::UnInit() FreeSocketMsgQueue(); FreeUdpMsgQueue(); - delete msg_mutex_; - msg_mutex_ = nullptr; - delete udp_msg_mutex_; - udp_msg_mutex_ = nullptr; - delete loop_cond_; - loop_cond_ = nullptr; - delete loop_mutex_; - loop_mutex_ = nullptr; a8::XPrintf("wsproxy terminated instance_id:%d pid:%d\n", {instance_id_, getpid()}); } diff --git a/server/wsproxy/app.h b/server/wsproxy/app.h index 34ca64b..aa662b6 100644 --- a/server/wsproxy/app.h +++ b/server/wsproxy/app.h @@ -78,15 +78,15 @@ private: std::set flags_; std::shared_ptr uuid_; - std::mutex *loop_mutex_ = nullptr; - std::condition_variable *loop_cond_ = nullptr; + std::shared_ptr loop_mutex_; + std::shared_ptr loop_cond_; - std::mutex* msg_mutex_ = nullptr; + std::shared_ptr msg_mutex_; MsgNode* top_node_ = nullptr; MsgNode* bot_node_ = nullptr; MsgNode* work_node_ = nullptr; - std::mutex* udp_msg_mutex_ = nullptr; + std::shared_ptr udp_msg_mutex_; UdpMsgNode* udp_top_node_ = nullptr; UdpMsgNode* udp_bot_node_ = nullptr; UdpMsgNode* udp_work_node_ = nullptr;