From 6a8c2848f6d6e754565dbd957372f2c3c7d894f9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 22 Dec 2017 10:37:07 +0100 Subject: 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. --- src/thread/Id.hxx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/thread/Id.hxx') 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 } /** -- cgit v1.2.3