(svn r13652) [NoAI] -Fix: throw thread-exit-signal with a custom class, not with the value '0', which might be captured by a lot of other layers
--- a/src/fiber_thread.cpp Mon Jun 30 10:26:40 2008 +0000
+++ b/src/fiber_thread.cpp Mon Jun 30 10:40:50 2008 +0000
@@ -119,7 +119,7 @@
try {
cur->m_proc(cur->m_param);
- } catch (...) {
+ } catch (OTTDThreadExitSignal e) {
/* Unlock the main thread */
s_main->m_sem->Set();
throw;
--- a/src/thread.h Mon Jun 30 10:26:40 2008 +0000
+++ b/src/thread.h Mon Jun 30 10:40:50 2008 +0000
@@ -7,6 +7,8 @@
typedef void (*OTTDThreadFunc)(void *);
+class OTTDThreadExitSignal { };
+
/**
* A Thread Object which works on all our supported OSes.
*/
--- a/src/thread_morphos.cpp Mon Jun 30 10:26:40 2008 +0000
+++ b/src/thread_morphos.cpp Mon Jun 30 10:40:50 2008 +0000
@@ -153,7 +153,7 @@
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 @@
if (NewGetTaskAttrs(NULL, &msg, sizeof(struct OTTDThreadStartupMessage *), TASKINFOTYPE_STARTUPMSG, TAG_DONE) && msg != NULL) {
try {
msg->func(msg->arg);
+ } catch(OTTDThreadExitSignal e) {
+ KPutStr("[Child] Returned to main()\n");
} catch(...) {
- KPutStr("[Child] Returned to main()\n");
+ NOT_REACHED();
}
}
--- a/src/thread_pthread.cpp Mon Jun 30 10:26:40 2008 +0000
+++ b/src/thread_pthread.cpp Mon Jun 30 10:40:50 2008 +0000
@@ -92,7 +92,7 @@
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 @@
/* 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 */
--- a/src/thread_win32.cpp Mon Jun 30 10:26:40 2008 +0000
+++ b/src/thread_win32.cpp Mon Jun 30 10:40:50 2008 +0000
@@ -87,7 +87,7 @@
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 @@
{
try {
m_proc(m_param);
+ } catch (OTTDExitSignal e) {
} catch (...) {
+ NOT_REACHED();
}
}
};