diff options
author | Kush <kush.agrawal@samsung.com> | 2019-11-21 21:24:26 +0530 |
---|---|---|
committer | DoHyun Pyun <dh79.pyun@samsung.com> | 2019-11-28 16:28:10 +0900 |
commit | bee5540a55f6e3416863a016d345bb1d8b328452 (patch) | |
tree | 17a478671c7a8a69b17432ce34d2df8238940f1c /resource/csdk/connectivity | |
parent | b133782529dcdbf8092b410a9e9b6cfc561c1eaa (diff) | |
download | iotivity-bee5540a55f6e3416863a016d345bb1d8b328452.tar.gz iotivity-bee5540a55f6e3416863a016d345bb1d8b328452.tar.bz2 iotivity-bee5540a55f6e3416863a016d345bb1d8b328452.zip |
Split TCP Server Mutex into different file
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>
Diffstat (limited to 'resource/csdk/connectivity')
-rwxr-xr-x[-rw-r--r--] | resource/csdk/connectivity/src/tcp_adapter/SConscript | 3 | ||||
-rwxr-xr-x | resource/csdk/connectivity/src/tcp_adapter/catcpserver.c | 115 | ||||
-rwxr-xr-x | resource/csdk/connectivity/src/tcp_adapter/catcpserver_mutex.c | 140 | ||||
-rwxr-xr-x | resource/csdk/connectivity/src/tcp_adapter/catcpserver_mutex.h | 68 |
4 files changed, 211 insertions, 115 deletions
diff --git a/resource/csdk/connectivity/src/tcp_adapter/SConscript b/resource/csdk/connectivity/src/tcp_adapter/SConscript index a1b88066c..cc3f8d3e8 100644..100755 --- a/resource/csdk/connectivity/src/tcp_adapter/SConscript +++ b/resource/csdk/connectivity/src/tcp_adapter/SConscript @@ -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')] diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c index f0ca652d8..2eb798c0b 100755 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c @@ -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 index 000000000..100c64b89 --- /dev/null +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpserver_mutex.c @@ -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 index 000000000..cedc7f050 --- /dev/null +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpserver_mutex.h @@ -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 |