diff options
Diffstat (limited to '')
-rw-r--r-- | src/common/mythread.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/common/mythread.h b/src/common/mythread.h new file mode 100644 index 00000000..cd9ae89a --- /dev/null +++ b/src/common/mythread.h @@ -0,0 +1,34 @@ +/////////////////////////////////////////////////////////////////////////////// +// +/// \file mythread.h +/// \brief Wrappers for threads +// +// Author: Lasse Collin +// This file has been put into the public domain. +// +/////////////////////////////////////////////////////////////////////////////// + +#include "sysdefs.h" + + +#ifdef HAVE_PTHREAD +# include <pthread.h> + +# define mythread_once(func) \ + do { \ + static pthread_once_t once_ = PTHREAD_ONCE_INIT; \ + pthread_once(&once_, &func); \ + } while (0) + +#else + +# define mythread_once(func) \ + do { \ + static bool once_ = false; \ + if (!once_) { \ + func(); \ + once_ = true; \ + } \ + } while (0) + +#endif |