summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-08-05 08:24:12 +0000
committertron <tron@openttd.org>2005-08-05 08:24:12 +0000
commit484fae74a2ab4a500496eec7af36dd8e34df105e (patch)
treeb50ada0cade250f81d3852f35d9bbe8bef601bae
parent062472161ade0d5e5c725d543b402e004efc175e (diff)
downloadopenttd-484fae74a2ab4a500496eec7af36dd8e34df105e.tar.xz
(svn r2807) Fix two major bugs in the threaded save code:
- Do not dereference a local variable which no longer exists; this lead to random crashes when saving - (Win32) Do not close a handle before it is used last There are still many major problems (race conditions and resulting memory corruption/crashes) left
-rw-r--r--functions.h1
-rw-r--r--os2.c6
-rw-r--r--saveload.c7
-rw-r--r--unix.c2
-rw-r--r--win32.c6
5 files changed, 3 insertions, 19 deletions
diff --git a/functions.h b/functions.h
index 6948a44d8..8537e6e13 100644
--- a/functions.h
+++ b/functions.h
@@ -279,6 +279,5 @@ void DeterminePaths(void);
void bubblesort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));
bool CreateOTTDThread(void *func, void *param);
-void CloseOTTDThread(void);
void JoinOTTDThread(void);
#endif /* FUNCTIONS_H */
diff --git a/os2.c b/os2.c
index 1e8039363..468c01c55 100644
--- a/os2.c
+++ b/os2.c
@@ -647,12 +647,6 @@ bool CreateOTTDThread(void *func, void *param)
return(true);
}
-void CloseOTTDThread(void)
-{
- _endthread();
- return;
-}
-
void JoinOTTDThread(void)
{
if (thread1 == 0)
diff --git a/saveload.c b/saveload.c
index f16730434..e036ae748 100644
--- a/saveload.c
+++ b/saveload.c
@@ -1292,7 +1292,6 @@ static bool SaveFileToDisk(void *ptr)
fclose(_sl.fh);
SaveFileDone();
- if (*(bool*)ptr) CloseOTTDThread();
return true;
}
@@ -1364,7 +1363,6 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode)
/* General tactic is to first save the game to memory, then use an available writer
* to write it to file, either in threaded mode if possible, or single-threaded */
if (mode == SL_SAVE) { /* SAVE game */
- bool threaded = true;
fmt = GetSavegameFormat("memory"); // write to memory
_sl.write_bytes = fmt->writer;
@@ -1381,10 +1379,9 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode)
SlWriteFill(); // flush the save buffer
/* Write to file */
- if (_network_server || !CreateOTTDThread(&SaveFileToDisk, &threaded)) {
+ if (_network_server || !CreateOTTDThread(&SaveFileToDisk, NULL)) {
DEBUG(misc, 1) ("cannot create savegame thread, reverting to single-threaded mode...");
- threaded = false;
- SaveFileToDisk(&threaded);
+ SaveFileToDisk(NULL);
}
} else { /* LOAD game */
diff --git a/unix.c b/unix.c
index 469be3e9e..cb13eb06d 100644
--- a/unix.c
+++ b/unix.c
@@ -530,8 +530,6 @@ bool CreateOTTDThread(void *func, void *param)
return pthread_create(&thread1, NULL, func, param) == 0;
}
-void CloseOTTDThread(void) {return;}
-
void JoinOTTDThread(void)
{
if (thread1 == 0) return;
diff --git a/win32.c b/win32.c
index ffd1754c0..f4857a075 100644
--- a/win32.c
+++ b/win32.c
@@ -1204,16 +1204,12 @@ bool CreateOTTDThread(void *func, void *param)
return hThread != NULL;
}
-void CloseOTTDThread(void)
-{
- if (!CloseHandle(hThread)) DEBUG(misc, 0) ("Failed to close thread?...");
-}
-
void JoinOTTDThread(void)
{
if (hThread == NULL) return;
WaitForSingleObject(hThread, INFINITE);
+ if (!CloseHandle(hThread)) DEBUG(misc, 0) ("Failed to close thread handle!");
}