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.
This commit is contained in:
Max Kellermann
2017-12-22 10:37:07 +01:00
parent 8649ea3d6f
commit 354104f9a9
3 changed files with 19 additions and 50 deletions

View File

@@ -52,13 +52,11 @@ public:
constexpr ThreadId(pthread_t _id):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
}
/**