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-debug.h"
26 #define DA_MUTEX_INIT(mutex_add, attr) {\
29 ret = pthread_mutex_init(mutex_add, attr);\
33 else if (EINVAL == ret) {\
34 DA_LOGE("pthread_mutex_init FAIL with EINVAL.");\
37 else if (ENOMEM == ret) {\
38 DA_LOGE("pthread_mutex_init FAIL with ENOMEM.");\
42 DA_LOGE("pthread_mutex_init FAIL with %d.", ret);\
48 #define DA_COND_INIT(cond_add, attr) do {\
49 if (0 != pthread_cond_init(cond_add, attr)) {\
50 DA_LOGE("pthread_cond_init FAIL");\
54 #define DA_MUTEX_LOCK(mutex_add) {\
57 ret = pthread_mutex_lock(mutex_add);\
61 else if (EINVAL == ret) {\
62 DA_LOGE("pthread_mutex_lock FAIL with EINVAL.");\
65 else if (EDEADLK == ret) {\
66 DA_LOGE("pthread_mutex_lock FAIL with EDEADLK.");\
70 DA_LOGE("pthread_mutex_lock FAIL with %d.", ret);\
76 #define DA_MUTEX_UNLOCK(mutex_add) {\
79 ret = pthread_mutex_unlock(mutex_add);\
83 else if (EINVAL == ret) {\
84 DA_LOGE("pthread_mutex_unlock FAIL with EINVAL.");\
87 else if (EPERM == ret) {\
88 DA_LOGE("pthread_mutex_unlock FAIL with EPERM.");\
92 DA_LOGE("pthread_mutex_unlock FAIL with %d.", ret);\
98 #define DA_COND_SIGNAL(cond_add) do {\
99 if (0 != pthread_cond_signal(cond_add)) {\
100 DA_LOGE("pthread_cond_signal FAIL");\
104 #define DA_COND_WAIT(cond_add, mutex_add) do {\
105 if (0 != pthread_cond_wait(cond_add, mutex_add)) {\
106 DA_LOGE("pthread_cond_wait FAIL");\
110 #define DA_COND_TIMED_WAIT(cond_add, mutex_add, time) do {\
111 if (0 != pthread_cond_timedwait(cond_add, mutex_add, time)) {\
112 DA_LOGE("pthread_cond_wait FAIL");\
117 #define DA_COND_DESTROY(cond_add) do {\
118 if (0 != pthread_cond_destroy(cond_add)) {\
119 DA_LOGE("pthread_cond_destroy FAIL");\
123 #define DA_MUTEX_DESTROY(mutex_add) {\
126 ret = pthread_mutex_destroy(mutex_add);\
130 else if (EINVAL == ret) {\
131 DA_LOGE("pthread_mutex_destroy FAIL with EINVAL.");\
134 else if (EBUSY == ret) {\
135 DA_LOGE("pthread_mutex_destroy FAIL with EBUSY.");\
139 DA_LOGE("pthread_mutex_destroy FAIL with %d.", ret);\