forked from Mirrorlandia_minetest/minetest
Fix race on thread creation
This often broke the threading tests on OSX.
This commit is contained in:
parent
e41673820f
commit
46fd114e9a
@ -116,9 +116,7 @@ bool Thread::start()
|
|||||||
#if USE_CPP11_THREADS
|
#if USE_CPP11_THREADS
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m_thread_obj = new std::thread(threadProc, this);
|
m_thread_obj = new std::thread(threadProc, this);
|
||||||
m_thread_id = m_thread_obj->get_id();
|
|
||||||
m_thread_handle = m_thread_obj->native_handle();
|
|
||||||
} catch (const std::system_error &e) {
|
} catch (const std::system_error &e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -135,8 +133,6 @@ bool Thread::start()
|
|||||||
if (status)
|
if (status)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_thread_id = m_thread_handle;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (!m_running)
|
while (!m_running)
|
||||||
@ -234,12 +230,6 @@ bool Thread::getReturnValue(void **ret)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Thread::isCurrentThread()
|
|
||||||
{
|
|
||||||
return thr_is_current_thread(m_thread_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#if USE_CPP11_THREADS || USE_POSIX_THREADS
|
#if USE_CPP11_THREADS || USE_POSIX_THREADS
|
||||||
void *Thread::threadProc(void *param)
|
void *Thread::threadProc(void *param)
|
||||||
#elif defined(_WIN32_WCE)
|
#elif defined(_WIN32_WCE)
|
||||||
|
@ -90,12 +90,22 @@ public:
|
|||||||
/*
|
/*
|
||||||
* Returns true if the calling thread is this Thread object.
|
* Returns true if the calling thread is this Thread object.
|
||||||
*/
|
*/
|
||||||
bool isCurrentThread();
|
bool isCurrentThread() { return thr_is_current_thread(getThreadId()); }
|
||||||
|
|
||||||
inline bool isRunning() { return m_running; }
|
inline bool isRunning() { return m_running; }
|
||||||
inline bool stopRequested() { return m_request_stop; }
|
inline bool stopRequested() { return m_request_stop; }
|
||||||
|
|
||||||
|
#if USE_CPP11_THREADS
|
||||||
|
inline threadid_t getThreadId() { return m_thread_obj->get_id(); }
|
||||||
|
inline threadhandle_t getThreadHandle() { return m_thread_obj->native_handle(); }
|
||||||
|
#else
|
||||||
|
# if USE_WIN_THREADS
|
||||||
inline threadid_t getThreadId() { return m_thread_id; }
|
inline threadid_t getThreadId() { return m_thread_id; }
|
||||||
|
# else
|
||||||
|
inline threadid_t getThreadId() { return m_thread_handle; }
|
||||||
|
# endif
|
||||||
inline threadhandle_t getThreadHandle() { return m_thread_handle; }
|
inline threadhandle_t getThreadHandle() { return m_thread_handle; }
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Gets the thread return value.
|
* Gets the thread return value.
|
||||||
@ -147,8 +157,12 @@ private:
|
|||||||
Atomic<bool> m_running;
|
Atomic<bool> m_running;
|
||||||
Mutex m_mutex;
|
Mutex m_mutex;
|
||||||
|
|
||||||
threadid_t m_thread_id;
|
#if !USE_CPP11_THREADS
|
||||||
threadhandle_t m_thread_handle;
|
threadhandle_t m_thread_handle;
|
||||||
|
#if _WIN32
|
||||||
|
threadid_t m_thread_id;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
static ThreadStartFunc threadProc;
|
static ThreadStartFunc threadProc;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user