mirror of
https://github.com/spiffcode/hostile-takeover.git
synced 2026-06-05 01:35:00 -06: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_;
|
pthread_key_t Thread::s_key_;
|
||||||
|
|
||||||
Thread::Thread(SocketServer *ss) : start_routine_(NULL), start_pv_(NULL),
|
Thread::Thread(SocketServer *ss) : start_routine_(NULL), start_pv_(NULL),
|
||||||
MessageQueue(ss) {
|
started_(false), MessageQueue(ss) {
|
||||||
static bool s_first_thread;
|
static bool s_first_thread;
|
||||||
if (!s_first_thread) {
|
if (!s_first_thread) {
|
||||||
pthread_key_create(&s_key_, NULL);
|
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) {
|
void *Thread::PreRun(void *pv) {
|
||||||
Thread *thread = (Thread *)pv;
|
Thread *thread = (Thread *)pv;
|
||||||
pthread_setspecific(s_key_, thread);
|
pthread_setspecific(s_key_, thread);
|
||||||
|
thread->started_ = true;
|
||||||
if (thread->start_routine_ != NULL) {
|
if (thread->start_routine_ != NULL) {
|
||||||
thread->start_routine_(thread->start_pv_);
|
thread->start_routine_(thread->start_pv_);
|
||||||
} else {
|
} else {
|
||||||
@ -44,7 +45,7 @@ void Thread::CallerStart(void *pv) {
|
|||||||
|
|
||||||
void Thread::Stop(bool wait) {
|
void Thread::Stop(bool wait) {
|
||||||
MessageQueue::Stop();
|
MessageQueue::Stop();
|
||||||
if (wait && ¤t() != this) {
|
if (wait && started_ && ¤t() != this) {
|
||||||
void *pv;
|
void *pv;
|
||||||
pthread_join(thread_, &pv);
|
pthread_join(thread_, &pv);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,7 @@ private:
|
|||||||
pthread_t thread_;
|
pthread_t thread_;
|
||||||
void (*start_routine_)(void *);
|
void (*start_routine_)(void *);
|
||||||
void *start_pv_;
|
void *start_pv_;
|
||||||
|
bool started_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace base
|
} // namespace base
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user