2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "download-provider-log.h"
22 #include "download-provider-pthread.h"
24 static char *__print_pthread_error(int code)
41 int dp_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
43 int ret = pthread_mutex_init(mutex, attr);
44 if (0 == ret || EBUSY == ret)
47 TRACE_ERROR("error:%d.%s", ret, __print_pthread_error(ret));
51 void dp_mutex_lock(pthread_mutex_t *mutex, const char *func, int line)
53 int ret = pthread_mutex_lock(mutex);
55 TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
56 __print_pthread_error(ret));
59 int dp_mutex_check_lock(pthread_mutex_t *mutex, const char *func, int line)
61 int ret = pthread_mutex_lock(mutex);
63 TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
64 __print_pthread_error(ret));
68 int dp_mutex_trylock(pthread_mutex_t *mutex, const char *func, int line)
70 int ret = pthread_mutex_trylock(mutex);
71 if (ret != 0 && ret != EINVAL) {
72 TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
73 __print_pthread_error(ret));
78 int dp_mutex_timedlock(pthread_mutex_t *mutex, int sec, const char *func, int line)
80 struct timespec deltatime;
81 deltatime.tv_sec = sec;
82 deltatime.tv_nsec = 0;
83 int ret = pthread_mutex_timedlock(mutex, &deltatime);
85 TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
86 __print_pthread_error(ret));
91 void dp_mutex_unlock(pthread_mutex_t *mutex, const char *func, int line)
93 int ret = pthread_mutex_unlock(mutex);
95 TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
96 __print_pthread_error(ret));
99 void dp_mutex_destroy(pthread_mutex_t *mutex)
101 int ret = pthread_mutex_destroy(mutex);
103 TRACE_ERROR("error:%d.%s", ret, __print_pthread_error(ret));
105 if (pthread_mutex_unlock(mutex) == 0)
106 pthread_mutex_destroy(mutex);