Split TCP Server Mutex into different file 00/218800/1
authorKush <kush.agrawal@samsung.com>
Thu, 21 Nov 2019 15:54:26 +0000 (21:24 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 28 Nov 2019 07:28:10 +0000 (16:28 +0900)
https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/commit/f2afffe9f976f4f5a6d44f41daa113f5b30eb410
(cherry-picked from f2afffe9f976f4f5a6d44f41daa113f5b30eb410)

Change-Id: If2106577547a02e4412ffdc4ce54c44b3eab5db8
Signed-off-by: Kush <kush.agrawal@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
resource/csdk/connectivity/src/tcp_adapter/SConscript [changed mode: 0644->0755]
resource/csdk/connectivity/src/tcp_adapter/catcpserver.c
resource/csdk/connectivity/src/tcp_adapter/catcpserver_mutex.c [new file with mode: 0755]
resource/csdk/connectivity/src/tcp_adapter/catcpserver_mutex.h [new file with mode: 0755]

old mode 100644 (file)
new mode 100755 (executable)
index a1b8806..cc3f8d3
@@ -18,7 +18,8 @@ common_files = None
 if target_os in ['linux', 'tizen', 'android', 'ios', 'tizenrt']:
     common_files = [
         os.path.join(src_dir, 'catcpadapter.c'),
-        os.path.join(src_dir, 'catcpserver.c') ]
+        os.path.join(src_dir, 'catcpserver.c'),
+        os.path.join(src_dir, 'catcpserver_mutex.c'),]
 else :
     common_files = [os.path.join(src_dir, 'catcpadapter.c')]
 
index f0ca652..2eb798c 100755 (executable)
@@ -49,6 +49,7 @@
 #include "caipnwmonitor.h"
 #include <coap/pdu.h>
 #include "caadapterutils.h"
+#include "catcpserver_mutex.h"
 #include "octhread.h"
 #include "oic_malloc.h"
 #include "oic_string.h"
@@ -94,26 +95,6 @@ static ca_thread_pool_t g_threadPool = NULL;
 static uint32_t g_taskId = 0;
 
 /**
- * Mutex to synchronize device object list.
- */
-static oc_mutex g_mutexObjectList = NULL;
-
-/**
- * Conditional mutex to synchronize.
- */
-static oc_cond g_condObjectList = NULL;
-
-/**
- * Mutex to synchronize send.
- */
-static oc_mutex g_mutexSend = NULL;
-
-/**
- * Conditional mutex to synchronize send.
- */
-static oc_cond g_condSend = NULL;
-
-/**
  * Maintains the callback to be notified when data received from remote device.
  */
 static CATCPPacketReceivedCallback g_packetReceivedCallback = NULL;
@@ -196,100 +177,6 @@ CAResult_t CASetTCPServerSocketBindIP(const char* ifname)
         FDS[COUNT].fd = caglobals.tcp.TYPE.fd; \
         FDS[COUNT].events = POLLIN;
 
-void CATCPDestroyMutex()
-{
-    if (g_mutexObjectList)
-    {
-        oc_mutex_free(g_mutexObjectList);
-        g_mutexObjectList = NULL;
-    }
-}
-
-CAResult_t CATCPCreateMutex()
-{
-    if (!g_mutexObjectList)
-    {
-        g_mutexObjectList = oc_mutex_new_recursive();
-        if (!g_mutexObjectList)
-        {
-            OIC_LOG(ERROR, TAG, "Failed to create mutex!");
-            return CA_STATUS_FAILED;
-        }
-    }
-
-    return CA_STATUS_OK;
-}
-
-void CATCPDestroyCond()
-{
-    if (g_condObjectList)
-    {
-        oc_cond_free(g_condObjectList);
-        g_condObjectList = NULL;
-    }
-}
-
-CAResult_t CATCPCreateCond()
-{
-    if (!g_condObjectList)
-    {
-        g_condObjectList = oc_cond_new();
-        if (!g_condObjectList)
-        {
-            OIC_LOG(ERROR, TAG, "Failed to create cond!");
-            return CA_STATUS_FAILED;
-        }
-    }
-    return CA_STATUS_OK;
-}
-
-void CATCPDestroySendMutex()
-{
-    if (g_mutexSend)
-    {
-        oc_mutex_free(g_mutexSend);
-        g_mutexSend = NULL;
-    }
-}
-
-CAResult_t CATCPCreateSendMutex()
-{
-    if (!g_mutexSend)
-    {
-        g_mutexSend = oc_mutex_new();
-        if (!g_mutexSend)
-        {
-            OIC_LOG(ERROR, TAG, "Failed to create send mutex!");
-            return CA_STATUS_FAILED;
-        }
-    }
-
-    return CA_STATUS_OK;
-}
-
-void CATCPDestroySendCond()
-{
-    if (g_condSend)
-    {
-        oc_cond_free(g_condSend);
-        g_condSend = NULL;
-    }
-}
-
-CAResult_t CATCPCreateSendCond()
-{
-    if (!g_condSend)
-    {
-        g_condSend = oc_cond_new();
-        if (!g_condSend)
-        {
-            OIC_LOG(ERROR, TAG, "Failed to create send cond!");
-            return CA_STATUS_FAILED;
-        }
-    }
-    return CA_STATUS_OK;
-}
-
 static void CAReceiveHandler(void *data)
 {
     (void)data;
diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpserver_mutex.c b/resource/csdk/connectivity/src/tcp_adapter/catcpserver_mutex.c
new file mode 100755 (executable)
index 0000000..100c64b
--- /dev/null
@@ -0,0 +1,140 @@
+/* ****************************************************************
+ *
+ * Copyright 2019 Samsung Electronics All Rights Reserved.
+ *
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ******************************************************************/
+
+#include "catcpserver_mutex.h"
+/**
+ * Logging tag for module name.
+ */
+//#define TAG "OIC_CA_TCP_SERVER"
+#define TAG TCP_SERVER_TAG
+
+/**
+ * Mutex to synchronize device object list.
+ */
+oc_mutex g_mutexObjectList = NULL;
+
+/**
+ * Conditional mutex to synchronize.
+ */
+oc_cond g_condObjectList= NULL;
+
+/**
+ * Mutex to synchronize send.
+ */
+oc_mutex g_mutexSend= NULL;
+
+/**
+ * Conditional mutex to synchronize send.
+ */
+oc_cond g_condSend= NULL;
+
+void CATCPDestroyMutex()
+{
+    if (g_mutexObjectList)
+    {
+        oc_mutex_free(g_mutexObjectList);
+        g_mutexObjectList = NULL;
+    }
+}
+
+CAResult_t CATCPCreateMutex()
+{
+    if (!g_mutexObjectList)
+    {
+        g_mutexObjectList = oc_mutex_new_recursive();
+        if (!g_mutexObjectList)
+        {
+            OIC_LOG(ERROR, TAG, "Failed to create mutex!");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    return CA_STATUS_OK;
+}
+
+void CATCPDestroyCond()
+{
+    if (g_condObjectList)
+    {
+        oc_cond_free(g_condObjectList);
+        g_condObjectList = NULL;
+    }
+}
+
+CAResult_t CATCPCreateCond()
+{
+    if (!g_condObjectList)
+    {
+        g_condObjectList = oc_cond_new();
+        if (!g_condObjectList)
+        {
+            OIC_LOG(ERROR, TAG, "Failed to create cond!");
+            return CA_STATUS_FAILED;
+        }
+    }
+    return CA_STATUS_OK;
+}
+
+void CATCPDestroySendMutex()
+{
+    if (g_mutexSend)
+    {
+        oc_mutex_free(g_mutexSend);
+        g_mutexSend = NULL;
+    }
+}
+
+CAResult_t CATCPCreateSendMutex()
+{
+    if (!g_mutexSend)
+    {
+        g_mutexSend = oc_mutex_new();
+        if (!g_mutexSend)
+        {
+            OIC_LOG(ERROR, TAG, "Failed to create send mutex!");
+            return CA_STATUS_FAILED;
+        }
+    }
+
+    return CA_STATUS_OK;
+}
+
+void CATCPDestroySendCond()
+{
+    if (g_condSend)
+    {
+        oc_cond_free(g_condSend);
+        g_condSend = NULL;
+    }
+}
+
+CAResult_t CATCPCreateSendCond()
+{
+    if (!g_condSend)
+    {
+        g_condSend = oc_cond_new();
+        if (!g_condSend)
+        {
+            OIC_LOG(ERROR, TAG, "Failed to create send cond!");
+            return CA_STATUS_FAILED;
+        }
+    }
+    return CA_STATUS_OK;
+}
diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpserver_mutex.h b/resource/csdk/connectivity/src/tcp_adapter/catcpserver_mutex.h
new file mode 100755 (executable)
index 0000000..cedc7f0
--- /dev/null
@@ -0,0 +1,68 @@
+/* ****************************************************************
+*
+* Copyright 2019 Samsung Electronics All Rights Reserved.
+*
+*
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*
+******************************************************************/
+
+#ifndef CA_TCP_SERVER_MUTEX_H_
+#define CA_TCP_SERVER_MUTEX_H_
+
+#include "octhread.h"
+#include "oic_malloc.h"
+#include "oic_string.h"
+#include "catcpinterface.h"
+#include "caipnwmonitor.h"
+#include <coap/pdu.h>
+#include "caadapterutils.h"
+
+/**
+ * Mutex to synchronize device object list.
+ */
+extern oc_mutex g_mutexObjectList;
+
+/**
+ * Conditional mutex to synchronize.
+ */
+extern oc_cond g_condObjectList;
+
+/**
+ * Mutex to synchronize send.
+ */
+extern oc_mutex g_mutexSend;
+
+/**
+ * Conditional mutex to synchronize send.
+ */
+extern oc_cond g_condSend;
+
+void CATCPDestroyMutex();
+
+CAResult_t CATCPCreateMutex();
+
+void CATCPDestroyCond();
+
+CAResult_t CATCPCreateCond();
+
+void CATCPDestroySendMutex();
+
+CAResult_t CATCPCreateSendMutex();
+
+void CATCPDestroySendCond();
+
+CAResult_t CATCPCreateSendCond();
+
+#endif