Merge branch 'v0.20.x'

This commit is contained in:
Max Kellermann
2018-01-15 09:06:31 +01:00
3 changed files with 19 additions and 2 deletions

View File

@@ -41,6 +41,16 @@ class Thread {
DWORD id;
#else
pthread_t handle = pthread_t();
#ifndef NDEBUG
/**
* This handle is only used by IsInside(), and is set by the
* thread function. Since #handle is set by pthread_create()
* which is racy, we need this attribute for early checks
* inside the thread function.
*/
pthread_t inside_handle = pthread_t();
#endif
#endif
public:
@@ -62,8 +72,9 @@ public:
#else
return handle != pthread_t();
#endif
}
}
#ifndef NDEBUG
/**
* Check if this thread is the current thread.
*/
@@ -78,9 +89,10 @@ public:
default-constructed values" (comment from
libstdc++) - and if both libstdc++ and libc++ get
away with this, we can do it as well */
return pthread_self() == handle;
return pthread_self() == inside_handle;
#endif
}
#endif
void Start();
void Join() noexcept;