1 /*
2 * Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <pthread.h>
19 #include <stdio.h>
20
21 #define TST_NO_DEFAULT_MAIN
22 #include "tst_test.h"
23
safe_pthread_create(const char * file,const int lineno,pthread_t * thread_id,const pthread_attr_t * attr,void * (* thread_fn)(void *),void * arg)24 int safe_pthread_create(const char *file, const int lineno,
25 pthread_t *thread_id, const pthread_attr_t *attr,
26 void *(*thread_fn)(void *), void *arg)
27 {
28 int rval;
29
30 rval = pthread_create(thread_id, attr, thread_fn, arg);
31
32 if (rval) {
33 tst_brk_(file, lineno, TBROK,
34 "pthread_create(%p,%p,%p,%p) failed: %s", thread_id,
35 attr, thread_fn, arg, tst_strerrno(rval));
36 }
37
38 return rval;
39 }
40
safe_pthread_join(const char * file,const int lineno,pthread_t thread_id,void ** retval)41 int safe_pthread_join(const char *file, const int lineno,
42 pthread_t thread_id, void **retval)
43 {
44 int rval;
45
46 rval = pthread_join(thread_id, retval);
47
48 if (rval) {
49 tst_brk_(file, lineno, TBROK,
50 "pthread_join(..., %p) failed: %s",
51 retval, tst_strerrno(rval));
52 }
53
54 return rval;
55 }
56