|
|
@@ -27,19 +27,16 @@ struct Private
|
|
|
#if CROWN_PLATFORM_POSIX
|
|
|
static void* thread_proc(void* arg)
|
|
|
{
|
|
|
- static s32 result = -1;
|
|
|
Thread* thread = (Thread*)arg;
|
|
|
thread->_sem.post();
|
|
|
- result = thread->_function(thread->_user_data);
|
|
|
- return (void*)&result;
|
|
|
+ return (void*)(uintptr_t)thread->_function(thread->_user_data);
|
|
|
}
|
|
|
#elif CROWN_PLATFORM_WINDOWS
|
|
|
static DWORD WINAPI thread_proc(void* arg)
|
|
|
{
|
|
|
Thread* thread = (Thread*)arg;
|
|
|
thread->_sem.post();
|
|
|
- s32 result = thread->_function(thread->_user_data);
|
|
|
- return result;
|
|
|
+ return thread->_function(thread->_user_data);
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
@@ -47,6 +44,7 @@ Thread::Thread()
|
|
|
: _function(NULL)
|
|
|
, _user_data(NULL)
|
|
|
, _is_running(false)
|
|
|
+ , _exit_code(0)
|
|
|
{
|
|
|
Private* priv = (Private*)_data;
|
|
|
CE_STATIC_ASSERT(sizeof(_data) >= sizeof(Private));
|
|
|
@@ -106,13 +104,15 @@ void Thread::stop()
|
|
|
CE_ASSERT(_is_running, "Thread is not running");
|
|
|
|
|
|
#if CROWN_PLATFORM_POSIX
|
|
|
- int err = pthread_join(priv->handle, NULL);
|
|
|
+ void* retval;
|
|
|
+ int err = pthread_join(priv->handle, &retval);
|
|
|
CE_ASSERT(err == 0, "pthread_join: errno = %d", err);
|
|
|
CE_UNUSED(err);
|
|
|
+ _exit_code = (s32)(uintptr_t)retval;
|
|
|
priv->handle = 0;
|
|
|
#elif CROWN_PLATFORM_WINDOWS
|
|
|
WaitForSingleObject(priv->handle, INFINITE);
|
|
|
- // GetExitCodeThread(_handle, &m_exit_code);
|
|
|
+ GetExitCodeThread(_handle, (DWORD*)&_exit_code);
|
|
|
CloseHandle(priv->handle);
|
|
|
priv->handle = INVALID_HANDLE_VALUE;
|
|
|
#endif
|
|
|
@@ -125,4 +125,9 @@ bool Thread::is_running()
|
|
|
return _is_running;
|
|
|
}
|
|
|
|
|
|
+s32 Thread::exit_code()
|
|
|
+{
|
|
|
+ return _exit_code;
|
|
|
+}
|
|
|
+
|
|
|
} // namespace crown
|