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 #include <mtp_thread.h>
22 mtp_bool _util_thread_create(pthread_t *tid, const mtp_char *tname,
23 mtp_int32 thread_state, thread_func_t thread_func, void *arg)
28 retv_if(tname == NULL, FALSE);
29 retv_if(thread_func == NULL, FALSE);
31 error = pthread_attr_init(&attr);
33 ERR("pthread_attr_init Fail [%d], errno [%d]\n", error, errno);
37 if (thread_state == PTHREAD_CREATE_JOINABLE) {
38 error = pthread_attr_setdetachstate(&attr,
39 PTHREAD_CREATE_JOINABLE);
41 ERR("pthread_attr_setdetachstate Fail [%d], errno [%d]\n", error, errno);
42 pthread_attr_destroy(&attr);
47 error = pthread_create(tid, &attr, thread_func, arg);
49 ERR("[%s] Thread creation Fail errno [%d]\n", tname, errno);
50 pthread_attr_destroy(&attr);
54 error = pthread_attr_destroy(&attr);
56 ERR("pthread_attr_destroy Fail [%d] errno [%d]\n", error, errno);
61 mtp_bool _util_thread_join(pthread_t tid, void **data)
65 res = pthread_join(tid, data);
67 ERR("pthread_join Fail res = [%d] for thread [%u] errno [%d]\n",
75 mtp_bool _util_thread_cancel(pthread_t tid)
79 res = pthread_cancel(tid);
81 ERR("pthread_cancel Fail [%d] errno [%d]\n", tid, errno);
88 void _util_thread_exit(void *val_ptr)
90 pthread_exit(val_ptr);