changeset 4323:26b70a40ebcd draft

(svn r5977) -Fix [FS#78]: never set I-am-a-thread bool to true IN the thread. Machines with dualcore can be faster then you want, and therefor create 2 threads, while you made the bool to make sure there is never more then 1 thread of this type.
author truelight <truelight@openttd.org>
date Sun, 20 Aug 2006 13:39:33 +0000
parents 635e7432d98e
children 79b2bec2c27a
files openttd.c openttd.h saveload.c
diffstat 3 files changed, 8 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/openttd.c
+++ b/openttd.c
@@ -535,9 +535,9 @@
 
 /** Mutex so that only one thread can communicate with the main program
  * at any given time */
-static ThreadMsg _message = 0;
+static ThreadMsg _message = MSG_OTTD_NO_MESSAGE;
 
-static inline void OTTD_ReleaseMutex(void) {_message = 0;}
+static inline void OTTD_ReleaseMutex(void) {_message = MSG_OTTD_NO_MESSAGE;}
 static inline ThreadMsg OTTD_PollThreadEvent(void) {return _message;}
 
 /** Called by running thread to execute some action in the main game.
@@ -545,7 +545,7 @@
 void OTTD_SendThreadMessage(ThreadMsg msg)
 {
 	if (_exit_game) return;
-	while (_message != 0) CSleep(10);
+	while (_message != MSG_OTTD_NO_MESSAGE) CSleep(10);
 
 	_message = msg;
 }
@@ -557,7 +557,6 @@
 static void ProcessSentMessage(ThreadMsg message)
 {
 	switch (message) {
-		case MSG_OTTD_SAVETHREAD_START: SaveFileStart(); break;
 		case MSG_OTTD_SAVETHREAD_DONE:  SaveFileDone(); break;
 		case MSG_OTTD_SAVETHREAD_ERROR: SaveFileError(); break;
 		default: NOT_REACHED();
--- a/openttd.h
+++ b/openttd.h
@@ -527,9 +527,9 @@
  * the OTTD_SendThreadMessage() function. Actions to perform upon the message are handled
  * in the ProcessSentMessage() function */
 typedef enum ThreadMsgs {
-	MSG_OTTD_SAVETHREAD_START  = 1,
-	MSG_OTTD_SAVETHREAD_DONE   = 2,
-	MSG_OTTD_SAVETHREAD_ERROR  = 3,
+	MSG_OTTD_NO_MESSAGE,
+	MSG_OTTD_SAVETHREAD_DONE,
+	MSG_OTTD_SAVETHREAD_ERROR,
 } ThreadMsg;
 
 void OTTD_SendThreadMessage(ThreadMsg msg);
--- a/saveload.c
+++ b/saveload.c
@@ -1402,8 +1402,6 @@
 	const SaveLoadFormat *fmt;
 	uint32 hdr[2];
 
-	if (arg != NULL) OTTD_SendThreadMessage(MSG_OTTD_SAVETHREAD_START);
-
 	/* XXX - Setup setjmp error handler if an error occurs anywhere deep during
 	 * loading/saving execute a longjmp() and continue execution here */
 	if (setjmp(_sl.excpt)) {
@@ -1536,10 +1534,12 @@
 		SlSaveChunks();
 		SlWriteFill(); // flush the save buffer
 
+		SaveFileStart();
 		if (_network_server ||
 					(save_thread = OTTDCreateThread(&SaveFileToDisk, (void*)"")) == NULL) {
 			DEBUG(misc, 1) ("[Sl] Cannot create savegame thread, reverting to single-threaded mode...");
 			SaveFileToDisk(NULL);
+			SaveFileDone();
 		}
 
 	} else { /* LOAD game */