Commit 96676f8f authored by Max Kellermann's avatar Max Kellermann

Merge branch 'v0.20.x'

parents 93b51d56 1f50bdb2
...@@ -25,6 +25,7 @@ ver 0.21 (not yet released) ...@@ -25,6 +25,7 @@ ver 0.21 (not yet released)
* require GCC 5.0 * require GCC 5.0
ver 0.20.16 (not yet released) ver 0.20.16 (not yet released)
* fix crash in debug build on Haiku and other operating systems
ver 0.20.15 (2018/01/05) ver 0.20.15 (2018/01/05)
* queue: fix crash after seek failure * queue: fix crash after seek failure
......
...@@ -86,6 +86,10 @@ Thread::ThreadProc(void *ctx) noexcept ...@@ -86,6 +86,10 @@ Thread::ThreadProc(void *ctx) noexcept
{ {
Thread &thread = *(Thread *)ctx; Thread &thread = *(Thread *)ctx;
#ifndef NDEBUG
thread.inside_handle = pthread_self();
#endif
thread.Run(); thread.Run();
return nullptr; return nullptr;
......
...@@ -41,6 +41,16 @@ class Thread { ...@@ -41,6 +41,16 @@ class Thread {
DWORD id; DWORD id;
#else #else
pthread_t handle = pthread_t(); 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 #endif
public: public:
...@@ -62,8 +72,9 @@ public: ...@@ -62,8 +72,9 @@ public:
#else #else
return handle != pthread_t(); return handle != pthread_t();
#endif #endif
} }
#ifndef NDEBUG
/** /**
* Check if this thread is the current thread. * Check if this thread is the current thread.
*/ */
...@@ -78,9 +89,10 @@ public: ...@@ -78,9 +89,10 @@ public:
default-constructed values" (comment from default-constructed values" (comment from
libstdc++) - and if both libstdc++ and libc++ get libstdc++) - and if both libstdc++ and libc++ get
away with this, we can do it as well */ away with this, we can do it as well */
return pthread_self() == handle; return pthread_self() == inside_handle;
#endif #endif
} }
#endif
void Start(); void Start();
void Join() noexcept; void Join() noexcept;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment