Fixed tinythread not supporting deleting detached thread objects.
This commit is contained in:
parent
1df896d6d1
commit
910feb0a07
2 changed files with 11 additions and 2 deletions
|
@ -176,8 +176,11 @@ void * thread::wrapper_function(void * aArg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// The thread is no longer executing
|
// The thread is no longer executing
|
||||||
lock_guard<mutex> guard(ti->mThread->mDataMutex);
|
if (ti->mThread){
|
||||||
ti->mThread->mNotAThread = true;
|
lock_guard<mutex> guard(ti->mThread->mDataMutex);
|
||||||
|
ti->mThread->mNotAThread = true;
|
||||||
|
ti->mThread->ti_copy = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// The thread is responsible for freeing the startup information
|
// The thread is responsible for freeing the startup information
|
||||||
delete ti;
|
delete ti;
|
||||||
|
@ -193,6 +196,7 @@ thread::thread(void (*aFunction)(void *), void * aArg)
|
||||||
// Fill out the thread startup information (passed to the thread wrapper,
|
// Fill out the thread startup information (passed to the thread wrapper,
|
||||||
// which will eventually free it)
|
// which will eventually free it)
|
||||||
_thread_start_info * ti = new _thread_start_info;
|
_thread_start_info * ti = new _thread_start_info;
|
||||||
|
ti_copy = ti;
|
||||||
ti->mFunction = aFunction;
|
ti->mFunction = aFunction;
|
||||||
ti->mArg = aArg;
|
ti->mArg = aArg;
|
||||||
ti->mThread = this;
|
ti->mThread = this;
|
||||||
|
@ -212,12 +216,16 @@ thread::thread(void (*aFunction)(void *), void * aArg)
|
||||||
if(!mHandle)
|
if(!mHandle)
|
||||||
{
|
{
|
||||||
mNotAThread = true;
|
mNotAThread = true;
|
||||||
|
ti_copy = 0;
|
||||||
delete ti;
|
delete ti;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
thread::~thread()
|
thread::~thread()
|
||||||
{
|
{
|
||||||
|
if (ti_copy){
|
||||||
|
((_thread_start_info *)ti_copy)->mThread = 0;
|
||||||
|
}
|
||||||
if(joinable())
|
if(joinable())
|
||||||
std::terminate();
|
std::terminate();
|
||||||
}
|
}
|
||||||
|
|
|
@ -554,6 +554,7 @@ class thread {
|
||||||
native_handle_type mHandle; ///< Thread handle.
|
native_handle_type mHandle; ///< Thread handle.
|
||||||
mutable mutex mDataMutex; ///< Serializer for access to the thread private data.
|
mutable mutex mDataMutex; ///< Serializer for access to the thread private data.
|
||||||
bool mNotAThread; ///< True if this object is not a thread of execution.
|
bool mNotAThread; ///< True if this object is not a thread of execution.
|
||||||
|
void * ti_copy;
|
||||||
#if defined(_TTHREAD_WIN32_)
|
#if defined(_TTHREAD_WIN32_)
|
||||||
unsigned int mWin32ThreadID; ///< Unique thread ID (filled out by _beginthreadex).
|
unsigned int mWin32ThreadID; ///< Unique thread ID (filled out by _beginthreadex).
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue