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)
42 int dp_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
44 int ret = pthread_mutex_init(mutex, attr);
45 if (0 == ret || EBUSY == ret)
48 TRACE_ERROR("error:%d.%s", ret, __print_pthread_error(ret));
52 void dp_mutex_lock(pthread_mutex_t *mutex, const char *func, int line)
54 int ret = pthread_mutex_lock(mutex);
56 TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
57 __print_pthread_error(ret));
60 int dp_mutex_check_lock(pthread_mutex_t *mutex, const char *func, int line)
62 int ret = pthread_mutex_lock(mutex);
64 TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
65 __print_pthread_error(ret));
69 int dp_mutex_trylock(pthread_mutex_t *mutex, const char *func, int line)
71 int ret = pthread_mutex_trylock(mutex);
72 if (ret != 0 && ret != EINVAL) {
73 TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
74 __print_pthread_error(ret));
79 int dp_mutex_timedlock(pthread_mutex_t *mutex, int sec, const char *func, int line)
81 struct timespec deltatime;
82 deltatime.tv_sec = sec;
83 deltatime.tv_nsec = 0;
84 int ret = pthread_mutex_timedlock(mutex, &deltatime);
86 TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
87 __print_pthread_error(ret));
92 void dp_mutex_unlock(pthread_mutex_t *mutex, const char *func, int line)
94 int ret = pthread_mutex_unlock(mutex);
96 TRACE_ERROR("%s:%d error:%d.%s", func, line, ret,
97 __print_pthread_error(ret));
100 void dp_mutex_destroy(pthread_mutex_t *mutex)
102 int ret = pthread_mutex_destroy(mutex);
104 TRACE_ERROR("error:%d.%s", ret, __print_pthread_error(ret));
106 if (pthread_mutex_unlock(mutex) == 0)
107 pthread_mutex_destroy(mutex);