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