Skip to content

Commit 46fd114

Browse files
committedApr 28, 2016
Fix race on thread creation
This often broke the threading tests on OSX.
1 parent e416738 commit 46fd114

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed
 

‎src/threading/thread.cpp

+1-11
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ bool Thread::start()
116116
#if USE_CPP11_THREADS
117117

118118
try {
119-
m_thread_obj = new std::thread(threadProc, this);
120-
m_thread_id = m_thread_obj->get_id();
121-
m_thread_handle = m_thread_obj->native_handle();
119+
m_thread_obj = new std::thread(threadProc, this);
122120
} catch (const std::system_error &e) {
123121
return false;
124122
}
@@ -135,8 +133,6 @@ bool Thread::start()
135133
if (status)
136134
return false;
137135

138-
m_thread_id = m_thread_handle;
139-
140136
#endif
141137

142138
while (!m_running)
@@ -234,12 +230,6 @@ bool Thread::getReturnValue(void **ret)
234230
}
235231

236232

237-
bool Thread::isCurrentThread()
238-
{
239-
return thr_is_current_thread(m_thread_id);
240-
}
241-
242-
243233
#if USE_CPP11_THREADS || USE_POSIX_THREADS
244234
void *Thread::threadProc(void *param)
245235
#elif defined(_WIN32_WCE)

‎src/threading/thread.h

+16-2
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,22 @@ class Thread {
9090
/*
9191
* Returns true if the calling thread is this Thread object.
9292
*/
93-
bool isCurrentThread();
93+
bool isCurrentThread() { return thr_is_current_thread(getThreadId()); }
9494

9595
inline bool isRunning() { return m_running; }
9696
inline bool stopRequested() { return m_request_stop; }
97+
98+
#if USE_CPP11_THREADS
99+
inline threadid_t getThreadId() { return m_thread_obj->get_id(); }
100+
inline threadhandle_t getThreadHandle() { return m_thread_obj->native_handle(); }
101+
#else
102+
# if USE_WIN_THREADS
97103
inline threadid_t getThreadId() { return m_thread_id; }
104+
# else
105+
inline threadid_t getThreadId() { return m_thread_handle; }
106+
# endif
98107
inline threadhandle_t getThreadHandle() { return m_thread_handle; }
108+
#endif
99109

100110
/*
101111
* Gets the thread return value.
@@ -147,8 +157,12 @@ class Thread {
147157
Atomic<bool> m_running;
148158
Mutex m_mutex;
149159

150-
threadid_t m_thread_id;
160+
#if !USE_CPP11_THREADS
151161
threadhandle_t m_thread_handle;
162+
#if _WIN32
Has a conversation. Original line has a conversation.
163+
threadid_t m_thread_id;
164+
#endif
165+
#endif
152166

153167
static ThreadStartFunc threadProc;
154168

0 commit comments

Comments
 (0)
Please sign in to comment.