mirror of
https://github.com/spiffcode/hostile-takeover.git
synced 2025-12-16 12:08:36 +00:00
Fix crash caused by trying to stop a thread that hasn't started.
This commit is contained in:
parent
6a0c49d05e
commit
b91e6e0b4b
@ -6,7 +6,7 @@ namespace base {
|
||||
pthread_key_t Thread::s_key_;
|
||||
|
||||
Thread::Thread(SocketServer *ss) : start_routine_(NULL), start_pv_(NULL),
|
||||
MessageQueue(ss) {
|
||||
started_(false), MessageQueue(ss) {
|
||||
static bool s_first_thread;
|
||||
if (!s_first_thread) {
|
||||
pthread_key_create(&s_key_, NULL);
|
||||
@ -28,6 +28,7 @@ void Thread::Start(void (start_routine)(void *), void *start_pv) {
|
||||
void *Thread::PreRun(void *pv) {
|
||||
Thread *thread = (Thread *)pv;
|
||||
pthread_setspecific(s_key_, thread);
|
||||
thread->started_ = true;
|
||||
if (thread->start_routine_ != NULL) {
|
||||
thread->start_routine_(thread->start_pv_);
|
||||
} else {
|
||||
@ -44,7 +45,7 @@ void Thread::CallerStart(void *pv) {
|
||||
|
||||
void Thread::Stop(bool wait) {
|
||||
MessageQueue::Stop();
|
||||
if (wait && ¤t() != this) {
|
||||
if (wait && started_ && ¤t() != this) {
|
||||
void *pv;
|
||||
pthread_join(thread_, &pv);
|
||||
}
|
||||
|
||||
@ -50,6 +50,7 @@ private:
|
||||
pthread_t thread_;
|
||||
void (*start_routine_)(void *);
|
||||
void *start_pv_;
|
||||
bool started_;
|
||||
};
|
||||
|
||||
} // namespace base
|
||||
|
||||
Loading…
Reference in New Issue
Block a user