(svn r2813) Plug a thread leak and prevent a race condition which could lead to multiple simultaneous saves and therefore severe corruption
authortron
Sat, 06 Aug 2005 07:15:17 +0000
changeset 2289 b0eb1b7f3eeb
parent 2288 57af8e0506f2
child 2290 3283963c5422
(svn r2813) Plug a thread leak and prevent a race condition which could lead to multiple simultaneous saves and therefore severe corruption
saveload.c
--- a/saveload.c	Fri Aug 05 20:22:06 2005 +0000
+++ b/saveload.c	Sat Aug 06 07:15:17 2005 +0000
@@ -1245,8 +1245,6 @@
 
 	tmp = _sl.buf;
 
-	SaveFileStart();
-
 	/* 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)) {
@@ -1325,6 +1323,8 @@
 		WaitTillSaved();
 		// nonsense to do an autosave while we were still saving our game, so skip it
 		if (_do_autosave) return SL_OK;
+	} else {
+		WaitTillSaved();
 	}
 
   /* Load a TTDLX or TTDPatch game */
@@ -1390,6 +1390,7 @@
 		SlWriteFill(); // flush the save buffer
 
 		/* Write to file */
+		SaveFileStart();
 		if (_network_server ||
 				(save_thread = OTTDCreateThread(&SaveFileToDisk, NULL)) == NULL) {
 			DEBUG(misc, 1) ("cannot create savegame thread, reverting to single-threaded mode...");