1 /* SPDX-License-Identifier: GPL-2.0-or-later 2 * Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved. 3 */ 4 5 #ifndef TST_SAFE_PTHREAD_H__ 6 #define TST_SAFE_PTHREAD_H__ 7 8 /* 9 * Macro to use for making functions called only once in 10 * multi-threaded tests such as init or cleanup function. 11 * The first call to @name_fn function by any thread shall 12 * call the @exec_fn. Subsequent calls shall not call @exec_fn. 13 * *_fn functions must not take any arguments. 14 */ 15 #define TST_DECLARE_ONCE_FN(name_fn, exec_fn) \ 16 void name_fn(void) \ 17 { \ 18 static pthread_once_t ltp_once = PTHREAD_ONCE_INIT; \ 19 pthread_once(<p_once, exec_fn); \ 20 } 21 22 int safe_pthread_create(const char *file, const int lineno, 23 pthread_t *thread_id, const pthread_attr_t *attr, 24 void *(*thread_fn)(void *), void *arg); 25 #define SAFE_PTHREAD_CREATE(thread_id, attr, thread_fn, arg) \ 26 safe_pthread_create(__FILE__, __LINE__, thread_id, attr, thread_fn, arg) 27 28 int safe_pthread_join(const char *file, const int lineno, 29 pthread_t thread_id, void **retval); 30 #define SAFE_PTHREAD_JOIN(thread_id, retval) \ 31 safe_pthread_join(__FILE__, __LINE__, thread_id, retval) 32 33 #endif /* TST_SAFE_PTHREAD_H__ */ 34