1 /* ****************************************************************
3 * Copyright 2019 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #include "catcpserver_mutex.h"
23 * Logging tag for module name.
25 //#define TAG "OIC_CA_TCP_SERVER"
26 #define TAG TCP_SERVER_TAG
29 * Mutex to synchronize device object list.
31 oc_mutex g_mutexObjectList = NULL;
34 * Conditional mutex to synchronize.
36 oc_cond g_condObjectList= NULL;
39 * Mutex to synchronize send.
41 oc_mutex g_mutexSend= NULL;
44 * Conditional mutex to synchronize send.
46 oc_cond g_condSend= NULL;
48 void CATCPDestroyMutex()
50 if (g_mutexObjectList)
52 oc_mutex_free(g_mutexObjectList);
53 g_mutexObjectList = NULL;
57 CAResult_t CATCPCreateMutex()
59 if (!g_mutexObjectList)
61 g_mutexObjectList = oc_mutex_new_recursive();
62 if (!g_mutexObjectList)
64 OIC_LOG(ERROR, TAG, "Failed to create mutex!");
65 return CA_STATUS_FAILED;
72 void CATCPDestroyCond()
76 oc_cond_free(g_condObjectList);
77 g_condObjectList = NULL;
81 CAResult_t CATCPCreateCond()
83 if (!g_condObjectList)
85 g_condObjectList = oc_cond_new();
86 if (!g_condObjectList)
88 OIC_LOG(ERROR, TAG, "Failed to create cond!");
89 return CA_STATUS_FAILED;
95 void CATCPDestroySendMutex()
99 oc_mutex_free(g_mutexSend);
104 CAResult_t CATCPCreateSendMutex()
108 g_mutexSend = oc_mutex_new();
111 OIC_LOG(ERROR, TAG, "Failed to create send mutex!");
112 return CA_STATUS_FAILED;
119 void CATCPDestroySendCond()
123 oc_cond_free(g_condSend);
128 CAResult_t CATCPCreateSendCond()
132 g_condSend = oc_cond_new();
135 OIC_LOG(ERROR, TAG, "Failed to create send cond!");
136 return CA_STATUS_FAILED;