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" 55 RawDoFmt(format, NULL, (
void (*)())RAWFMTFUNC_SERIAL, NULL);
65 struct MsgPort *m_replyport;
74 m_thr(0), self_destruct(self_destruct)
78 KPutStr(
"[OpenTTD] Create thread...\n");
80 parent = FindTask(NULL);
83 SetTaskPri(parent, 0);
89 m_replyport = CreateMsgPort();
91 if (m_replyport != NULL) {
92 struct Process *child;
94 m_msg.msg.mn_Node.ln_Type = NT_MESSAGE;
95 m_msg.msg.mn_ReplyPort = m_replyport;
98 child = CreateNewProcTags(
99 NP_CodeType, CODETYPE_PPC,
101 NP_StartupMsg, (IPTR)&m_msg,
103 NP_Name, (IPTR)
"OpenTTD Thread",
104 NP_PPCStackSize, 131072UL,
107 m_thr = (APTR) child;
110 KPutStr(
"[OpenTTD] Child process launched.\n");
112 KPutStr(
"[OpenTTD] Couldn't create child process. (constructors never fail, yeah!)\n");
113 DeleteMsgPort(m_replyport);
129 KPutStr(
"[Child] Aborting...\n");
131 if (NewGetTaskAttrs(NULL, &msg,
sizeof(
struct OTTDThreadStartupMessage *), TASKINFOTYPE_STARTUPMSG, TAG_DONE) && msg != NULL) {
144 assert(!IsCurrent());
146 KPutStr(
"[OpenTTD] Join threads...\n");
147 KPutStr(
"[OpenTTD] Wait for child to quit...\n");
148 WaitPort(m_replyport);
151 DeleteMsgPort(m_replyport);
157 return FindTask(NULL) == m_thr;
167 struct Task *child = FindTask(NULL);
171 SetTaskPri(child, -5);
173 KPutStr(
"[Child] Progressing...\n");
175 if (NewGetTaskAttrs(NULL, &msg,
sizeof(
struct OTTDThreadStartupMessage *), TASKINFOTYPE_STARTUPMSG, TAG_DONE) && msg != NULL) {
179 KPutStr(
"[Child] Returned to main()\n");
188 if (self_destruct)
delete this;
195 if (thread != NULL) *thread = to;
void * arg
functions arguments for the thread function
void(* OTTDThreadFunc)(void *)
Definition of all thread entry functions.
struct Message msg
standard exec.library message (MUST be the first thing in the message struct!)
MorphOS version for ThreadObject.
bool Exit()
Exit this thread.
APTR m_thr
System thread identifier.
OTTDThreadFunc func
function the thread will execute
avoid name clashes with MorphOS API functions
void Join()
Join this thread.
static void Proxy()
On thread creation, this function is called, which calls the real startup function.
ThreadObject_MorphOS(OTTDThreadFunc proc, void *param, self_destruct)
Create a sub process and start it, calling proc(param).
A Thread Object which works on all our supported OSes.
Signal used for signalling we knowingly want to end the thread.
static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread=NULL, const char *name=NULL)
Create a thread; proc will be called as first function inside the thread, with optional params...
void KPutStr(CONST_STRPTR format)
Default OpenTTD STDIO/ERR debug output is not very useful for this, so we utilize serial/ramdebug ins...