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.
This commit is contained in:
		
							
								
								
									
										1
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								NEWS
									
									
									
									
									
								
							| @@ -1,4 +1,5 @@ | |||||||
| ver 0.18.15 (not yet released) | ver 0.18.15 (not yet released) | ||||||
|  | * work around build failure on NetBSD | ||||||
|  |  | ||||||
| ver 0.18.14 (2014/09/11) | ver 0.18.14 (2014/09/11) | ||||||
| * protocol | * protocol | ||||||
|   | |||||||
| @@ -28,7 +28,7 @@ struct notify { | |||||||
| 	Cond cond; | 	Cond cond; | ||||||
| 	bool pending; | 	bool pending; | ||||||
|  |  | ||||||
| #ifndef WIN32 | #if !defined(WIN32) && !defined(__NetBSD__) | ||||||
| 	constexpr | 	constexpr | ||||||
| #endif | #endif | ||||||
| 	notify():pending(false) {} | 	notify():pending(false) {} | ||||||
|   | |||||||
| @@ -41,7 +41,21 @@ class PosixCond { | |||||||
| 	pthread_cond_t cond; | 	pthread_cond_t cond; | ||||||
|  |  | ||||||
| public: | 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) {} | 	constexpr PosixCond():cond(PTHREAD_COND_INITIALIZER) {} | ||||||
|  | #endif | ||||||
|  |  | ||||||
| 	PosixCond(const PosixCond &other) = delete; | 	PosixCond(const PosixCond &other) = delete; | ||||||
| 	PosixCond &operator=(const PosixCond &other) = delete; | 	PosixCond &operator=(const PosixCond &other) = delete; | ||||||
|   | |||||||
| @@ -41,7 +41,21 @@ class PosixMutex { | |||||||
| 	pthread_mutex_t mutex; | 	pthread_mutex_t mutex; | ||||||
|  |  | ||||||
| public: | 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) {} | 	constexpr PosixMutex():mutex(PTHREAD_MUTEX_INITIALIZER) {} | ||||||
|  | #endif | ||||||
|  |  | ||||||
| 	PosixMutex(const PosixMutex &other) = delete; | 	PosixMutex(const PosixMutex &other) = delete; | ||||||
| 	PosixMutex &operator=(const PosixMutex &other) = delete; | 	PosixMutex &operator=(const PosixMutex &other) = delete; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann