equal
deleted
inserted
replaced
100 /* You cannot join yourself */ |
100 /* You cannot join yourself */ |
101 assert(!IsCurrent()); |
101 assert(!IsCurrent()); |
102 |
102 |
103 pthread_join(m_thr, NULL); |
103 pthread_join(m_thr, NULL); |
104 m_thr = 0; |
104 m_thr = 0; |
105 |
|
106 delete this; |
|
107 } |
105 } |
108 |
106 |
109 /* virtual */ bool IsCurrent() |
107 /* virtual */ bool IsCurrent() |
110 { |
108 { |
111 return pthread_self() == m_thr; |
109 return pthread_self() == m_thr; |
134 void ThreadProc() |
132 void ThreadProc() |
135 { |
133 { |
136 /* The new thread stops here so the calling thread can complete pthread_create() call */ |
134 /* The new thread stops here so the calling thread can complete pthread_create() call */ |
137 sem_wait(&m_sem_start); |
135 sem_wait(&m_sem_start); |
138 |
136 |
139 /* Did this thread die naturally/via exit, or did it join? */ |
|
140 bool exit = false; |
|
141 |
|
142 /* Call the proc of the creator to continue this thread */ |
137 /* Call the proc of the creator to continue this thread */ |
143 try { |
138 try { |
144 m_proc(m_param); |
139 m_proc(m_param); |
145 } catch (...) { |
140 } catch (...) { |
146 exit = true; |
|
147 } |
141 } |
148 |
142 |
149 /* Notify threads waiting for our completion */ |
143 /* Notify threads waiting for our completion */ |
150 sem_post(&m_sem_stop); |
144 sem_post(&m_sem_stop); |
151 |
|
152 if (exit) delete this; |
|
153 } |
145 } |
154 }; |
146 }; |
155 |
147 |
156 /* static */ ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param) |
148 /* static */ ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param) |
157 { |
149 { |