summaryrefslogtreecommitdiff
path: root/src/thread_morphos.cpp
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2008-06-08 12:06:27 +0000
committertruebrain <truebrain@openttd.org>2008-06-08 12:06:27 +0000
commite767b4f7784ba8e0f52cb920a4b171ef9b61e67f (patch)
tree824116881f6d5514cdaa069f10eddac84da3b04a /src/thread_morphos.cpp
parent4657ae97fcd9487adb882f8634ad5cfe589d034c (diff)
downloadopenttd-e767b4f7784ba8e0f52cb920a4b171ef9b61e67f.tar.xz
(svn r13412) -Add: OTTDThreadTerminateFunc, for all thread systems, which is called when a thread is terminated. Now GenWorld- and SaveLoad-thread cleanup theirselves correctly, while Fibers don't (as that causes access-violations)
Diffstat (limited to 'src/thread_morphos.cpp')
-rw-r--r--src/thread_morphos.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/thread_morphos.cpp b/src/thread_morphos.cpp
index ef074da45..6df33baac 100644
--- a/src/thread_morphos.cpp
+++ b/src/thread_morphos.cpp
@@ -57,6 +57,7 @@ void KPutStr(CONST_STRPTR format)
class ThreadObject_MorphOS : public ThreadObject {
private:
APTR m_thr; ///< System thread identifier.
+ OTTDThreadTerminateFunc m_terminate_func; ///< Function to call on thread termination.
struct MsgPort *m_replyport;
struct OTTDThreadStartupMessage m_msg;
@@ -64,7 +65,9 @@ public:
/**
* Create a sub process and start it, calling proc(param).
*/
- ThreadObject_MorphOS(OTTDThreadFunc proc, void *param) : m_thr(0)
+ ThreadObject_MorphOS(OTTDThreadFunc proc, void *param, OTTDThreadTerminateFunc terminate_func) :
+ m_thr(0),
+ m_terminate_func(terminate_func)
{
struct Task *parent;
@@ -111,7 +114,9 @@ public:
/**
* Create a thread and attach current thread to it.
*/
- ThreadObject_MorphOS() : m_thr(0)
+ ThreadObject_MorphOS() :
+ m_thr(0),
+ m_terminate_func(NULL)
{
m_thr = FindTask(NULL);
}
@@ -210,12 +215,14 @@ private:
/* Quit the child, exec.library will reply the startup msg internally. */
KPutStr("[Child] Done.\n");
+
+ if (this->terminate_func != NULL) this->terminate_func(this);
}
};
-/* static */ ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param)
+/* static */ ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param, OTTDThreadTerminateFunc terminate_func)
{
- return new ThreadObject_MorphOS(proc, param);
+ return new ThreadObject_MorphOS(proc, param, terminate_func);
}
/* static */ ThreadObject *ThreadObject::AttachCurrent()