summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/thread.h2
-rw-r--r--src/thread_morphos.cpp6
-rw-r--r--src/thread_pthread.cpp4
-rw-r--r--src/thread_win32.cpp4
4 files changed, 12 insertions, 4 deletions
diff --git a/src/thread.h b/src/thread.h
index f6f29a711..8d0a8ee84 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -7,6 +7,8 @@
typedef void (*OTTDThreadFunc)(void *);
+class OTTDThreadExitSignal { };
+
/**
* A Thread Object which works on all our supported OSes.
*/
diff --git a/src/thread_morphos.cpp b/src/thread_morphos.cpp
index ef074da45..fcf459d04 100644
--- a/src/thread_morphos.cpp
+++ b/src/thread_morphos.cpp
@@ -153,7 +153,7 @@ public:
if (NewGetTaskAttrs(NULL, &msg, sizeof(struct OTTDThreadStartupMessage *), TASKINFOTYPE_STARTUPMSG, TAG_DONE) && msg != NULL) {
/* For now we terminate by throwing an error, gives much cleaner cleanup */
- throw 0;
+ throw OTTDThreadExitSignal();
}
return true;
@@ -203,8 +203,10 @@ private:
if (NewGetTaskAttrs(NULL, &msg, sizeof(struct OTTDThreadStartupMessage *), TASKINFOTYPE_STARTUPMSG, TAG_DONE) && msg != NULL) {
try {
msg->func(msg->arg);
- } catch(...) {
+ } catch(OTTDThreadExitSignal e) {
KPutStr("[Child] Returned to main()\n");
+ } catch(...) {
+ NOT_REACHED();
}
}
diff --git a/src/thread_pthread.cpp b/src/thread_pthread.cpp
index b3f340b6a..2fbca79b2 100644
--- a/src/thread_pthread.cpp
+++ b/src/thread_pthread.cpp
@@ -92,7 +92,7 @@ public:
if (!IsRunning()) return false;
/* For now we terminate by throwing an error, gives much cleaner cleanup */
- throw 0;
+ throw OTTDThreadExitSignal();
}
/* virtual */ void Join()
@@ -137,7 +137,9 @@ private:
/* Call the proc of the creator to continue this thread */
try {
m_proc(m_param);
+ } catch (OTTDThreadExitSignal e) {
} catch (...) {
+ NOT_REACHED();
}
/* Notify threads waiting for our completion */
diff --git a/src/thread_win32.cpp b/src/thread_win32.cpp
index 6f12a6fbc..83bb5a76a 100644
--- a/src/thread_win32.cpp
+++ b/src/thread_win32.cpp
@@ -87,7 +87,7 @@ public:
if (!IsRunning()) return false;
/* For now we terminate by throwing an error, gives much cleaner cleanup */
- throw 0;
+ throw OTTDThreadExitSignal();
}
/* virtual */ void Join()
@@ -128,7 +128,9 @@ private:
{
try {
m_proc(m_param);
+ } catch (OTTDThreadExitSignal) {
} catch (...) {
+ NOT_REACHED();
}
}
};