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;
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...