Commit 5ba5bc8b authored by Max Kellermann's avatar Max Kellermann

thread/Thread: move code to Run()

parent 82c66ce0
...@@ -74,6 +74,26 @@ Thread::Join() ...@@ -74,6 +74,26 @@ Thread::Join()
#endif #endif
} }
inline void
Thread::Run()
{
#ifndef WIN32
#ifndef NDEBUG
/* this works around a race condition that causes an assertion
failure due to IsInside() spuriously returning false right
after the thread has been created, and the calling thread
hasn't initialised "defined" yet */
defined = true;
#endif
#endif
f(ctx);
#ifdef ANDROID
Java::DetachCurrentThread();
#endif
}
#ifdef WIN32 #ifdef WIN32
DWORD WINAPI DWORD WINAPI
...@@ -81,7 +101,7 @@ Thread::ThreadProc(LPVOID ctx) ...@@ -81,7 +101,7 @@ Thread::ThreadProc(LPVOID ctx)
{ {
Thread &thread = *(Thread *)ctx; Thread &thread = *(Thread *)ctx;
thread.f(thread.ctx); thread.Run();
return 0; return 0;
} }
...@@ -92,19 +112,7 @@ Thread::ThreadProc(void *ctx) ...@@ -92,19 +112,7 @@ Thread::ThreadProc(void *ctx)
{ {
Thread &thread = *(Thread *)ctx; Thread &thread = *(Thread *)ctx;
#ifndef NDEBUG thread.Run();
/* this works around a race condition that causes an assertion
failure due to IsInside() spuriously returning false right
after the thread has been created, and the calling thread
hasn't initialised "defined" yet */
thread.defined = true;
#endif
thread.f(thread.ctx);
#ifdef ANDROID
Java::DetachCurrentThread();
#endif
return nullptr; return nullptr;
} }
......
...@@ -93,6 +93,8 @@ public: ...@@ -93,6 +93,8 @@ public:
void Join(); void Join();
private: private:
void Run();
#ifdef WIN32 #ifdef WIN32
static DWORD WINAPI ThreadProc(LPVOID ctx); static DWORD WINAPI ThreadProc(LPVOID ctx);
#else #else
......
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