summaryrefslogtreecommitdiff
path: root/src/thread/Id.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2017-12-22 10:37:07 +0100
committerMax Kellermann <max@musicpd.org>2017-12-22 10:37:07 +0100
commit6a8c2848f6d6e754565dbd957372f2c3c7d894f9 (patch)
tree09881134cb9abe26711ee734179f1076b5c3dbd3 /src/thread/Id.hxx
parent6439727afc515bc0244d8be020e6946dbf6bca10 (diff)
thread/{Thread,Id}: use defaul-initialized pthread_t as "undefined" value
Use the "==" operator instead of pthread_equal(). This allows us to eliminate two boolean flags which are there to avoid race conditions, and made the thing so fragile that I got tons of (correct) thread sanitizer warnings.
Diffstat (limited to 'src/thread/Id.hxx')
-rw-r--r--src/thread/Id.hxx16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/thread/Id.hxx b/src/thread/Id.hxx
index 17cdfa0d2..7fc6a4d80 100644
--- a/src/thread/Id.hxx
+++ b/src/thread/Id.hxx
@@ -52,13 +52,11 @@ public:
constexpr ThreadId(pthread_t _id) noexcept:id(_id) {}
#endif
- gcc_const
- static ThreadId Null() noexcept {
+ static constexpr ThreadId Null() noexcept {
#ifdef _WIN32
return 0;
#else
- static ThreadId null;
- return null;
+ return pthread_t();
#endif
}
@@ -81,11 +79,13 @@ public:
gcc_pure
bool operator==(const ThreadId &other) const noexcept {
-#ifdef _WIN32
+ /* note: not using pthread_equal() because that
+ function "is undefined if either thread ID is not
+ valid so we can't safely use it on
+ default-constructed values" (comment from
+ libstdc++) - and if both libstdc++ and libc++ get
+ away with this, we can do it as well */
return id == other.id;
-#else
- return pthread_equal(id, other.id);
-#endif
}
/**