From: Kush Date: Thu, 21 Nov 2019 15:54:26 +0000 (+0530) Subject: Split TCP Server Mutex into different file X-Git-Tag: submit/tizen/20191128.075235~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bee5540a55f6e3416863a016d345bb1d8b328452;p=platform%2Fupstream%2Fiotivity.git 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 Signed-off-by: DoHyun Pyun --- diff --git a/resource/csdk/connectivity/src/tcp_adapter/SConscript b/resource/csdk/connectivity/src/tcp_adapter/SConscript old mode 100644 new mode 100755 index a1b88066c..cc3f8d3e8 --- 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 #include "caadapterutils.h" +#include "catcpserver_mutex.h" #include "octhread.h" #include "oic_malloc.h" #include "oic_string.h" @@ -93,26 +94,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. */ @@ -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 +#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