12 #include "../stdafx.h" 
   15 #include "../core/alloc_func.hpp" 
   19 #include <exec/types.h> 
   20 #include <exec/rawfmt.h> 
   21 #include <dos/dostags.h> 
   23 #include <proto/dos.h> 
   24 #include <proto/exec.h> 
   26 #include "../safeguards.h" 
   53 #ifndef NO_DEBUG_MESSAGES 
   56   RawDoFmt(format, NULL, (
void (*)())RAWFMTFUNC_SERIAL, NULL);
 
   69   struct MsgPort *m_replyport;
 
   78     m_thr(0), self_destruct(self_destruct)
 
   82     KPutStr(
"[OpenTTD] Create thread...\n");
 
   84     parent = FindTask(NULL);
 
   87     SetTaskPri(parent, 0);
 
   93     m_replyport = CreateMsgPort();
 
   95     if (m_replyport != NULL) {
 
   96       struct Process *child;
 
   98       m_msg.
msg.mn_Node.ln_Type = NT_MESSAGE;
 
   99       m_msg.
msg.mn_ReplyPort    = m_replyport;
 
  102       child = CreateNewProcTags(
 
  103         NP_CodeType,     CODETYPE_PPC,
 
  105         NP_StartupMsg,   (IPTR)&m_msg,
 
  107         NP_Name,         (IPTR)
"OpenTTD Thread",
 
  108         NP_PPCStackSize, 131072UL,
 
  111       m_thr = (APTR) child;
 
  114         KPutStr(
"[OpenTTD] Child process launched.\n");
 
  116         KPutStr(
"[OpenTTD] Couldn't create child process. (constructors never fail, yeah!)\n");
 
  117         DeleteMsgPort(m_replyport);
 
  133     KPutStr(
"[Child] Aborting...\n");
 
  135     if (NewGetTaskAttrs(NULL, &msg, 
sizeof(
struct OTTDThreadStartupMessage *), TASKINFOTYPE_STARTUPMSG, TAG_DONE) && msg != NULL) {
 
  148     assert(!IsCurrent());
 
  150     KPutStr(
"[OpenTTD] Join threads...\n");
 
  151     KPutStr(
"[OpenTTD] Wait for child to quit...\n");
 
  152     WaitPort(m_replyport);
 
  155     DeleteMsgPort(m_replyport);
 
  161     return FindTask(NULL) == 
m_thr;
 
  171     struct Task *child = FindTask(NULL);
 
  175     SetTaskPri(child, -5);
 
  177     KPutStr(
"[Child] Progressing...\n");
 
  179     if (NewGetTaskAttrs(NULL, &msg, 
sizeof(
struct OTTDThreadStartupMessage *), TASKINFOTYPE_STARTUPMSG, TAG_DONE) && msg != NULL) {
 
  183         KPutStr(
"[Child] Returned to main()\n");
 
  192     if (self_destruct) 
delete this;
 
  199   if (thread != NULL) *thread = to;