4 * Copyright (c) 2012 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include "cal_internal.h"
23 #include "cal_typedef.h"
24 #include "cal_mutex.h"
26 static pthread_mutex_t _cal_property_hash_mutex = PTHREAD_MUTEX_INITIALIZER;
27 static pthread_mutex_t _cal_connection_mutex = PTHREAD_MUTEX_INITIALIZER;
28 static pthread_mutex_t _cal_pims_ipc_call_mutex = PTHREAD_MUTEX_INITIALIZER;
29 static pthread_mutex_t _cal_inotify_mutex = PTHREAD_MUTEX_INITIALIZER;
30 static pthread_mutex_t _cal_pims_ipc_pubsub_mutex = PTHREAD_MUTEX_INITIALIZER;
31 static pthread_mutex_t _cal_access_control_mutex = PTHREAD_MUTEX_INITIALIZER;
32 static pthread_mutex_t _cal_timeout_mutex = PTHREAD_MUTEX_INITIALIZER;
33 static pthread_mutex_t _cal_handle_mutex = PTHREAD_MUTEX_INITIALIZER;
35 static inline pthread_mutex_t* _cal_mutex_get_mutex(int type)
37 pthread_mutex_t *ret_val;
40 case CAL_MUTEX_PROPERTY_HASH:
41 ret_val = &_cal_property_hash_mutex;
43 case CAL_MUTEX_CONNECTION:
44 ret_val = &_cal_connection_mutex;
46 case CAL_MUTEX_PIMS_IPC_CALL:
47 ret_val = &_cal_pims_ipc_call_mutex;
49 case CAL_MUTEX_INOTIFY:
50 ret_val = &_cal_inotify_mutex;
52 case CAL_MUTEX_PIMS_IPC_PUBSUB:
53 ret_val = &_cal_pims_ipc_pubsub_mutex;
55 case CAL_MUTEX_ACCESS_CONTROL:
56 ret_val = &_cal_access_control_mutex;
58 case CAL_MUTEX_TIMEOUT:
59 ret_val = &_cal_timeout_mutex;
61 case CAL_MUTEX_HANDLE:
62 ret_val = &_cal_handle_mutex;
66 ERR("unknown type(%d)", type);
74 void cal_mutex_lock(int type)
77 pthread_mutex_t *mutex;
79 mutex = _cal_mutex_get_mutex(type);
82 ret = pthread_mutex_lock(mutex);
83 RETM_IF(ret, "pthread_mutex_lock() Fail(%d)", ret);
87 void cal_mutex_unlock(int type)
90 pthread_mutex_t *mutex;
92 mutex = _cal_mutex_get_mutex(type);
95 ret = pthread_mutex_unlock(mutex);
96 RETM_IF(ret, "pthread_mutex_unlock() Fail(%d)", ret);