From e304d0f8ee404ef7e1223a324012d4fb4049185d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 13 Sep 2014 11:26:17 +0200 Subject: 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. --- src/thread/PosixCond.hxx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/thread/PosixCond.hxx') 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; -- cgit v1.2.3