aboutsummaryrefslogtreecommitdiffstats
path: root/src/thread
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-09-13 11:26:17 +0200
committerMax Kellermann <max@duempel.org>2014-09-13 11:26:17 +0200
commite304d0f8ee404ef7e1223a324012d4fb4049185d (patch)
treee2e6b0c018541f6746d7f704bcb10743ca08ed53 /src/thread
parentab7b38d4b9c6673dc4adfaed7956984ec6bc8c9e (diff)
downloadmpd-e304d0f8ee404ef7e1223a324012d4fb4049185d.tar.gz
mpd-e304d0f8ee404ef7e1223a324012d4fb4049185d.tar.xz
mpd-e304d0f8ee404ef7e1223a324012d4fb4049185d.zip
thread/Posix{Cond,Mutex}: don't ues PTHREAD_*_INITIALIZER on NetBSD
On NetBSD, PTHREAD_MUTEX_INITIALIZER and PTHREAD_COND_INITIALIZER are not compatible with C++11 "constexpr" (see Mantis ticket 0004110). As a workaround, don't ues "constexpr", and use the functions pthread_mutex_init(), pthread_mutex_destroy(), pthread_cond_init() and pthread_cond_destroy() instead. This adds some runtime overhead, but is portable to POSIX implementations that have awkward initializer macros.
Diffstat (limited to 'src/thread')
-rw-r--r--src/thread/PosixCond.hxx14
-rw-r--r--src/thread/PosixMutex.hxx14
2 files changed, 28 insertions, 0 deletions
diff --git a/src/thread/PosixCond.hxx b/src/thread/PosixCond.hxx
index 6f98d3ad0..c2797649a 100644
--- a/src/thread/PosixCond.hxx
+++ b/src/thread/PosixCond.hxx
@@ -41,7 +41,21 @@ class PosixCond {
pthread_cond_t cond;
public:
+#ifdef __NetBSD__
+ /* NetBSD's PTHREAD_COND_INITIALIZER is not compatible with
+ "constexpr" */
+ PosixCond() {
+ pthread_cond_init(&cond, nullptr);
+ }
+
+ ~PosixCond() {
+ pthread_cond_destroy(&cond);
+ }
+#else
+ /* optimized constexpr constructor for sane POSIX
+ implementations */
constexpr PosixCond():cond(PTHREAD_COND_INITIALIZER) {}
+#endif
PosixCond(const PosixCond &other) = delete;
PosixCond &operator=(const PosixCond &other) = delete;
diff --git a/src/thread/PosixMutex.hxx b/src/thread/PosixMutex.hxx
index d50764af4..445c0ace2 100644
--- a/src/thread/PosixMutex.hxx
+++ b/src/thread/PosixMutex.hxx
@@ -41,7 +41,21 @@ class PosixMutex {
pthread_mutex_t mutex;
public:
+#ifdef __NetBSD__
+ /* NetBSD's PTHREAD_MUTEX_INITIALIZER is not compatible with
+ "constexpr" */
+ PosixMutex() {
+ pthread_mutex_init(&mutex, nullptr);
+ }
+
+ ~PosixMutex() {
+ pthread_mutex_destroy(&mutex);
+ }
+#else
+ /* optimized constexpr constructor for sane POSIX
+ implementations */
constexpr PosixMutex():mutex(PTHREAD_MUTEX_INITIALIZER) {}
+#endif
PosixMutex(const PosixMutex &other) = delete;
PosixMutex &operator=(const PosixMutex &other) = delete;