2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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 _MTP_THREAD_H_
18 #define _MTP_THREAD_H_
21 #include "mtp_datatype.h"
24 typedef void *(*thread_func_t) (void *pArg);
26 #define UTIL_LOCK_MUTEX(mut)\
29 DBG("Thread [%d] trying to lock the Mutex \n", syscall(__NR_gettid));\
30 lock_ret = pthread_mutex_lock(mut);\
32 if(lock_ret == EDEADLK) {\
33 DBG("Mutex is already locked by the same thread");\
35 ERR("Error locking mutex. Error = %d \n", lock_ret);\
38 DBG("Mutex locked by thread [%d] \n", syscall(__NR_gettid));\
43 #define UTIL_UNLOCK_MUTEX(mut)\
46 unlock_ret = pthread_mutex_unlock(mut);\
47 if (unlock_ret != 0) {\
48 ERR("Error unlocking mutex. Error = %d \n", unlock_ret);\
50 DBG("Mutex unlocked by thread [%d] \n", syscall(__NR_gettid));\
54 mtp_bool _util_thread_create(pthread_t *tid, const mtp_char *tname,
55 mtp_int32 thread_state, thread_func_t thread_func, void *arg);
56 mtp_bool _util_thread_join(pthread_t tid, void **data);
57 mtp_bool _util_thread_cancel(pthread_t tid);
58 void _util_thread_exit(void *val_ptr);
60 #endif /*_MTP_THREAD_H_*/