Add a lock at channel 70/225570/1 accepted/tizen/unified/20200224.081505 submit/tizen/20200221.070719
authorBoram Bae <boram21.bae@samsung.com>
Fri, 21 Feb 2020 03:38:08 +0000 (12:38 +0900)
committerBoram Bae <boram21.bae@samsung.com>
Fri, 21 Feb 2020 03:42:44 +0000 (12:42 +0900)
Change-Id: Ied812242c1eda6b0adb1878b3fbc2a9bc85b2d1f
Signed-off-by: Boram Bae <boram21.bae@samsung.com>
src/shared/channel.cpp
src/shared/channel.h

index 6ae8ed3..7077723 100644 (file)
@@ -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<message> 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];
index 4aeefbc..719dca2 100644 (file)
@@ -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<uint64_t> m_pending_event_id;
 
        std::atomic<bool> m_connected;
+       cmutex m_cmutex;
 };
 
 }