equal
deleted
inserted
replaced
32 |
32 |
33 struct OTTDThreadStartupMessage { |
33 struct OTTDThreadStartupMessage { |
34 struct Message msg; ///< standard exec.library message (MUST be the first thing in the message struct!) |
34 struct Message msg; ///< standard exec.library message (MUST be the first thing in the message struct!) |
35 OTTDThreadFunc func; ///< function the thread will execute |
35 OTTDThreadFunc func; ///< function the thread will execute |
36 void *arg; ///< functions arguments for the thread function |
36 void *arg; ///< functions arguments for the thread function |
37 void *ret; ///< return value of the thread function |
|
38 }; |
37 }; |
39 |
38 |
40 |
39 |
41 /** |
40 /** |
42 * Default OpenTTD STDIO/ERR debug output is not very useful for this, so we |
41 * Default OpenTTD STDIO/ERR debug output is not very useful for this, so we |
77 SetTaskPri(parent, 0); |
76 SetTaskPri(parent, 0); |
78 |
77 |
79 /* Things we'll pass down to the child by utilizing NP_StartupMsg */ |
78 /* Things we'll pass down to the child by utilizing NP_StartupMsg */ |
80 m_msg.func = proc; |
79 m_msg.func = proc; |
81 m_msg.arg = param; |
80 m_msg.arg = param; |
82 m_msg.ret = NULL; |
|
83 |
81 |
84 m_replyport = CreateMsgPort(); |
82 m_replyport = CreateMsgPort(); |
85 |
83 |
86 if (m_replyport != NULL) { |
84 if (m_replyport != NULL) { |
87 struct Process *child; |
85 struct Process *child; |
159 } |
157 } |
160 |
158 |
161 return true; |
159 return true; |
162 } |
160 } |
163 |
161 |
164 /* virtual */ void *Join() |
162 /* virtual */ void Join() |
165 { |
163 { |
166 struct OTTDThreadStartupMessage *reply; |
164 struct OTTDThreadStartupMessage *reply; |
167 void *ret; |
|
168 |
165 |
169 /* You cannot join yourself */ |
166 /* You cannot join yourself */ |
170 assert(!IsCurrent()); |
167 assert(!IsCurrent()); |
171 |
168 |
172 KPutStr("[OpenTTD] Join threads...\n"); |
169 KPutStr("[OpenTTD] Join threads...\n"); |
173 KPutStr("[OpenTTD] Wait for child to quit...\n"); |
170 KPutStr("[OpenTTD] Wait for child to quit...\n"); |
174 WaitPort(m_replyport); |
171 WaitPort(m_replyport); |
175 |
172 |
176 reply = (struct OTTDThreadStartupMessage *)GetMsg(m_replyport); |
173 GetMsg(m_replyport); |
177 ret = reply->ret; |
|
178 |
|
179 DeleteMsgPort(m_replyport); |
174 DeleteMsgPort(m_replyport); |
180 m_thr = 0; |
175 m_thr = 0; |
181 |
|
182 return ret; |
|
183 } |
176 } |
184 |
177 |
185 /* virtual */ bool IsCurrent() |
178 /* virtual */ bool IsCurrent() |
186 { |
179 { |
187 return FindTask(NULL) == m_thr; |
180 return FindTask(NULL) == m_thr; |
207 |
200 |
208 KPutStr("[Child] Progressing...\n"); |
201 KPutStr("[Child] Progressing...\n"); |
209 |
202 |
210 if (NewGetTaskAttrs(NULL, &msg, sizeof(struct OTTDThreadStartupMessage *), TASKINFOTYPE_STARTUPMSG, TAG_DONE) && msg != NULL) { |
203 if (NewGetTaskAttrs(NULL, &msg, sizeof(struct OTTDThreadStartupMessage *), TASKINFOTYPE_STARTUPMSG, TAG_DONE) && msg != NULL) { |
211 try { |
204 try { |
212 msg->ret = msg->func(msg->arg); |
205 msg->func(msg->arg); |
213 } catch(...) { |
206 } catch(...) { |
214 KPutStr("[Child] Returned to main()\n"); |
207 KPutStr("[Child] Returned to main()\n"); |
215 } |
208 } |
216 } |
209 } |
217 |
210 |
254 |
247 |
255 } |
248 } |
256 |
249 |
257 /* virtual */ void Set() |
250 /* virtual */ void Set() |
258 { |
251 { |
259 // Check if semaphore count is really important there. |
252 /* Check if semaphore count is really important there. */ |
260 ReleaseSemaphore(&m_sem); |
253 ReleaseSemaphore(&m_sem); |
261 } |
254 } |
262 |
255 |
263 /* virtual */ void Wait() |
256 /* virtual */ void Wait() |
264 { |
257 { |