xref: /dragonfly/contrib/xz/src/common/mythread.h (revision 3170ffd7)
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       mythread.h
4 /// \brief      Wrappers for threads
5 //
6 //  Author:     Lasse Collin
7 //
8 //  This file has been put into the public domain.
9 //  You can do whatever you want with this file.
10 //
11 ///////////////////////////////////////////////////////////////////////////////
12 
13 #include "sysdefs.h"
14 
15 
16 #ifdef HAVE_PTHREAD
17 #	include <pthread.h>
18 
19 #	define mythread_once(func) \
20 	do { \
21 		static pthread_once_t once_ = PTHREAD_ONCE_INIT; \
22 		pthread_once(&once_, &func); \
23 	} while (0)
24 
25 #	define mythread_sigmask(how, set, oset) \
26 		pthread_sigmask(how, set, oset)
27 
28 #else
29 
30 #	define mythread_once(func) \
31 	do { \
32 		static bool once_ = false; \
33 		if (!once_) { \
34 			func(); \
35 			once_ = true; \
36 		} \
37 	} while (0)
38 
39 #	define mythread_sigmask(how, set, oset) \
40 		sigprocmask(how, set, oset)
41 
42 #endif
43