thread/Posix{Mutex,Cond}: use "constexpr" only with glibc
Apparently all other C libraries are not compatible with "constexpr". Those which are not will get a performance penalty, but at least they work at all.
This commit is contained in:
parent
f0b58c6f24
commit
75dff64450
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2009-2013 Max Kellermann <max@duempel.org>
|
* Copyright (C) 2009-2015 Max Kellermann <max@duempel.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -41,9 +41,13 @@ class PosixCond {
|
|||||||
pthread_cond_t cond;
|
pthread_cond_t cond;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#if defined(__NetBSD__) || defined(__BIONIC__)
|
#ifdef __GLIBC__
|
||||||
/* NetBSD's PTHREAD_COND_INITIALIZER is not compatible with
|
/* optimized constexpr constructor for pthread implementations
|
||||||
"constexpr" */
|
that support it */
|
||||||
|
constexpr PosixCond():cond(PTHREAD_COND_INITIALIZER) {}
|
||||||
|
#else
|
||||||
|
/* slow fallback for pthread implementations that are not
|
||||||
|
compatible with "constexpr" */
|
||||||
PosixCond() {
|
PosixCond() {
|
||||||
pthread_cond_init(&cond, nullptr);
|
pthread_cond_init(&cond, nullptr);
|
||||||
}
|
}
|
||||||
@ -51,10 +55,6 @@ public:
|
|||||||
~PosixCond() {
|
~PosixCond() {
|
||||||
pthread_cond_destroy(&cond);
|
pthread_cond_destroy(&cond);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
/* optimized constexpr constructor for sane POSIX
|
|
||||||
implementations */
|
|
||||||
constexpr PosixCond():cond(PTHREAD_COND_INITIALIZER) {}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PosixCond(const PosixCond &other) = delete;
|
PosixCond(const PosixCond &other) = delete;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2009-2013 Max Kellermann <max@duempel.org>
|
* Copyright (C) 2009-2015 Max Kellermann <max@duempel.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
@ -41,9 +41,13 @@ class PosixMutex {
|
|||||||
pthread_mutex_t mutex;
|
pthread_mutex_t mutex;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#if defined(__NetBSD__) || defined(__BIONIC__)
|
#ifdef __GLIBC__
|
||||||
/* NetBSD's PTHREAD_MUTEX_INITIALIZER is not compatible with
|
/* optimized constexpr constructor for pthread implementations
|
||||||
"constexpr" */
|
that support it */
|
||||||
|
constexpr PosixMutex():mutex(PTHREAD_MUTEX_INITIALIZER) {}
|
||||||
|
#else
|
||||||
|
/* slow fallback for pthread implementations that are not
|
||||||
|
compatible with "constexpr" */
|
||||||
PosixMutex() {
|
PosixMutex() {
|
||||||
pthread_mutex_init(&mutex, nullptr);
|
pthread_mutex_init(&mutex, nullptr);
|
||||||
}
|
}
|
||||||
@ -51,10 +55,6 @@ public:
|
|||||||
~PosixMutex() {
|
~PosixMutex() {
|
||||||
pthread_mutex_destroy(&mutex);
|
pthread_mutex_destroy(&mutex);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
/* optimized constexpr constructor for sane POSIX
|
|
||||||
implementations */
|
|
||||||
constexpr PosixMutex():mutex(PTHREAD_MUTEX_INITIALIZER) {}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PosixMutex(const PosixMutex &other) = delete;
|
PosixMutex(const PosixMutex &other) = delete;
|
||||||
|
Loading…
Reference in New Issue
Block a user