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.
17 #ifndef _Download_Agent_Pthread_H
18 #define _Download_Agent_Pthread_H
24 #include "download-agent-type.h"
25 #include "download-agent-debug.h"
27 #define _da_thread_mutex_init(mutex_add, attr) { \
30 ret = pthread_mutex_init(mutex_add, attr); \
34 else if(EINVAL == ret){ \
35 DA_LOG_ERR(Default, "pthread_mutex_init FAIL with EINVAL."); \
38 else if(ENOMEM == ret){ \
39 DA_LOG_ERR(Default, "pthread_mutex_init FAIL with ENOMEM."); \
43 DA_LOG_ERR(Default, "pthread_mutex_init FAIL with %d.", ret); \
49 #define _da_thread_cond_init(cond_add, attr) do{ \
50 if (0 != pthread_cond_init(cond_add, attr)){\
51 DA_LOG_ERR(Default, "pthread_cond_init FAIL");} \
56 #define _da_thread_mutex_lock(mutex_add) {\
59 ret = pthread_mutex_lock(mutex_add);\
63 else if(EINVAL == ret){\
64 DA_LOG_ERR(Default, "pthread_mutex_lock FAIL with EINVAL.");\
67 else if(EDEADLK == ret){\
68 DA_LOG_ERR(Default, "pthread_mutex_lock FAIL with EDEADLK.");\
72 DA_LOG_ERR(Default, "pthread_mutex_lock FAIL with %d.", ret);\
79 #define _da_thread_mutex_unlock(mutex_add) {\
82 ret = pthread_mutex_unlock(mutex_add);\
86 else if(EINVAL == ret){\
87 DA_LOG_ERR(Default, "pthread_mutex_unlock FAIL with EINVAL.");\
90 else if(EPERM == ret){\
91 DA_LOG_ERR(Default, "pthread_mutex_unlock FAIL with EPERM.");\
95 DA_LOG_ERR(Default, "pthread_mutex_unlock FAIL with %d.", ret);\
102 #define _da_thread_cond_signal(cond_add) do{ \
103 if (0 != pthread_cond_signal(cond_add)){\
104 DA_LOG_ERR(Default, "pthread_cond_signal FAIL");} \
109 #define _da_thread_cond_wait(cond_add, mutex_add) do{ \
110 if (0 != pthread_cond_wait(cond_add, mutex_add)){\
111 DA_LOG_ERR(Default, "pthread_cond_wait FAIL");} \
114 #define _da_thread_cond_timed_wait(cond_add, mutex_add, time) do{ \
115 if (0 != pthread_cond_timedwait(cond_add, mutex_add, time)){\
116 DA_LOG_ERR(Default, "pthread_cond_wait FAIL");} \
120 #define _da_thread_cond_destroy(cond_add) do{ \
121 if (0 != pthread_cond_destroy(cond_add)){\
122 DA_LOG_ERR(Default, "pthread_cond_destroy FAIL");} \
125 #define _da_thread_mutex_destroy(mutex_add) {\
128 ret = pthread_mutex_destroy(mutex_add);\
132 else if(EINVAL == ret){\
133 DA_LOG_ERR(Default, "pthread_mutex_destroy FAIL with EINVAL.");\
136 else if(EBUSY == ret){\
137 DA_LOG_ERR(Default, "pthread_mutex_destroy FAIL with EBUSY.");\
141 DA_LOG_ERR(Default, "pthread_mutex_destroy FAIL with %d.", ret);\