From: Boram Bae Date: Fri, 21 Feb 2020 03:38:08 +0000 (+0900) Subject: Add a lock at channel X-Git-Tag: accepted/tizen/unified/20200224.081505^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1eb04ba6d14c9a3bd8d8299dcef105a00a22da80;p=platform%2Fcore%2Fsystem%2Fsensord.git Add a lock at channel Change-Id: Ied812242c1eda6b0adb1878b3fbc2a9bc85b2d1f Signed-off-by: Boram Bae --- diff --git a/src/shared/channel.cpp b/src/shared/channel.cpp index 6ae8ed3..7077723 100644 --- a/src/shared/channel.cpp +++ b/src/shared/channel.cpp @@ -116,7 +116,9 @@ channel::channel(socket *sock) channel::~channel() { _D("Destroyed[%llu]", m_event_id); - disconnect(); + if (is_connected()) { + disconnect(); + } } uint64_t channel::bind(void) @@ -158,6 +160,7 @@ uint64_t channel::connect(channel_handler *handler, event_loop *loop, bool loop_ void channel::disconnect(void) { + AUTOLOCK(m_cmutex); if (!is_connected()) { _D("Channel is not connected"); return; @@ -224,6 +227,12 @@ bool channel::send(std::shared_ptr msg) bool channel::send_sync(message &msg) { + AUTOLOCK(m_cmutex); + if (!is_connected()) { + _D("Channel is not connected"); + return false; + } + retvm_if(msg.size() >= MAX_MSG_CAPACITY, true, "Invaild message size[%u]", msg.size()); ssize_t size = 0; @@ -264,6 +273,12 @@ bool channel::read(void) bool channel::read_sync(message &msg, bool select) { + AUTOLOCK(m_cmutex); + if (!is_connected()) { + _D("Channel is not connected"); + return false; + } + message_header header; ssize_t size = 0; char buf[MAX_MSG_CAPACITY]; diff --git a/src/shared/channel.h b/src/shared/channel.h index 4aeefbc..719dca2 100644 --- a/src/shared/channel.h +++ b/src/shared/channel.h @@ -28,6 +28,7 @@ #include "message.h" #include "event_loop.h" #include "channel_handler.h" +#include "cmutex.h" namespace ipc { @@ -68,6 +69,7 @@ private: std::vector m_pending_event_id; std::atomic m_connected; + cmutex m_cmutex; }; }