aboutsummaryrefslogtreecommitdiff
path: root/src/common/mythread.h
diff options
context:
space:
mode:
authorMartin Matuska <mm@FreeBSD.org>2010-05-07 18:59:06 +0000
committerMartin Matuska <mm@FreeBSD.org>2010-05-07 18:59:06 +0000
commitc19dc90688c2dacd857449ee2edceb09c3811e20 (patch)
tree930e9402a94c661612fa29e89b59d7b967d4d1aa /src/common/mythread.h
Notes
Diffstat (limited to 'src/common/mythread.h')
-rw-r--r--src/common/mythread.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/common/mythread.h b/src/common/mythread.h
new file mode 100644
index 000000000000..476c2fc9e103
--- /dev/null
+++ b/src/common/mythread.h
@@ -0,0 +1,42 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+/// \file mythread.h
+/// \brief Wrappers for threads
+//
+// Author: Lasse Collin
+//
+// This file has been put into the public domain.
+// You can do whatever you want with this file.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#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)
+
+# define mythread_sigmask(how, set, oset) \
+ pthread_sigmask(how, set, oset)
+
+#else
+
+# define mythread_once(func) \
+ do { \
+ static bool once_ = false; \
+ if (!once_) { \
+ func(); \
+ once_ = true; \
+ } \
+ } while (0)
+
+# define mythread_sigmask(how, set, oset) \
+ sigprocmask(how, set, oset)
+
+#endif