mirror of https://gitee.com/bigwinds/arangodb
don't fiddle with thread structs that were not initialized yet (#6979)
This commit is contained in:
parent
4e7f56a532
commit
29383d1082
|
@ -138,6 +138,7 @@ std::string Thread::stringify(ThreadState state) {
|
|||
/// @brief constructs a thread
|
||||
Thread::Thread(std::string const& name, bool deleteOnExit)
|
||||
: _deleteOnExit(deleteOnExit),
|
||||
_threadStructInitialized(false),
|
||||
_name(name),
|
||||
_thread(),
|
||||
_threadNumber(0),
|
||||
|
@ -155,12 +156,14 @@ Thread::~Thread() {
|
|||
<< "delete(" << _name << "), state: " << stringify(state);
|
||||
|
||||
if (state == ThreadState::STOPPED) {
|
||||
if (TRI_IsSelfThread(&_thread)) {
|
||||
// we must ignore any errors here, but TRI_DetachThread will log them
|
||||
TRI_DetachThread(&_thread);
|
||||
} else {
|
||||
// we must ignore any errors here, but TRI_JoinThread will log them
|
||||
TRI_JoinThread(&_thread);
|
||||
if (_threadStructInitialized) {
|
||||
if (TRI_IsSelfThread(&_thread)) {
|
||||
// we must ignore any errors here, but TRI_DetachThread will log them
|
||||
TRI_DetachThread(&_thread);
|
||||
} else {
|
||||
// we must ignore any errors here, but TRI_JoinThread will log them
|
||||
TRI_JoinThread(&_thread);
|
||||
}
|
||||
}
|
||||
|
||||
_state.store(ThreadState::DETACHED);
|
||||
|
@ -282,6 +285,9 @@ bool Thread::start(ConditionVariable* finishedCondition) {
|
|||
return false;
|
||||
}
|
||||
|
||||
TRI_ASSERT(!_threadStructInitialized);
|
||||
memset(&_thread, 0, sizeof(thread_t));
|
||||
|
||||
bool ok =
|
||||
TRI_StartThread(&_thread, &_threadId, _name.c_str(), &startThread, this);
|
||||
|
||||
|
@ -295,6 +301,8 @@ bool Thread::start(ConditionVariable* finishedCondition) {
|
|||
cleanupMe();
|
||||
}
|
||||
|
||||
_threadStructInitialized = true;
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
|
|
@ -151,6 +151,7 @@ class Thread {
|
|||
|
||||
private:
|
||||
bool const _deleteOnExit;
|
||||
bool _threadStructInitialized;
|
||||
|
||||
// name of the thread
|
||||
std::string const _name;
|
||||
|
|
Loading…
Reference in New Issue