(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 noai
authortruebrain
Mon, 30 Jun 2008 10:40:50 +0000
branchnoai
changeset 11095 a0da321a39b3
parent 11094 72be0534cd0f
child 11096 4c9f93632d0b
(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
src/fiber_thread.cpp
src/thread.h
src/thread_morphos.cpp
src/thread_pthread.cpp
src/thread_win32.cpp
--- 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();
 		}
 	}
 };