diff options
author | Michael Lutz <michi@icosahedron.de> | 2019-03-11 00:45:39 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2019-04-06 11:27:39 +0200 |
commit | 05f4e7360886e36b221ef5c3af4426625a3de686 (patch) | |
tree | 27aed9756e80eca86ff95f5805901a80048b0fb1 /src/openttd.cpp | |
parent | 3b86f54fc739510277f434c68e17a93ab6448ed4 (diff) | |
download | openttd-05f4e7360886e36b221ef5c3af4426625a3de686.tar.xz |
Codechange: Replace custom mutex code with C++11 mutex'es.
A conforming compiler with a valid <mutex>-header is expected.
Most parts of the code assume that locking a mutex will never fail unexpectedly,
which is generally true on all common platforms that don't just pretend to
be C++11. The use of condition variables in driver code is checked.
Diffstat (limited to 'src/openttd.cpp')
-rw-r--r-- | src/openttd.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/openttd.cpp b/src/openttd.cpp index 29319236a..180de64b0 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -68,6 +68,7 @@ #include "linkgraph/linkgraphschedule.h" #include <stdarg.h> +#include <system_error> #include "safeguards.h" @@ -547,6 +548,9 @@ int openttd_main(int argc, char *argv[]) extern bool _dedicated_forks; _dedicated_forks = false; + std::unique_lock<std::mutex> modal_work_lock(_modal_progress_work_mutex, std::defer_lock); + std::unique_lock<std::mutex> modal_paint_lock(_modal_progress_paint_mutex, std::defer_lock); + _game_mode = GM_MENU; _switch_mode = SM_MENU; _config_file = NULL; @@ -830,8 +834,14 @@ int openttd_main(int argc, char *argv[]) free(musicdriver); /* Take our initial lock on whatever we might want to do! */ - _modal_progress_paint_mutex->BeginCritical(); - _modal_progress_work_mutex->BeginCritical(); + try { + modal_work_lock.lock(); + modal_paint_lock.lock(); + } catch (const std::system_error&) { + /* If there is some error we assume that threads aren't usable on the system we run. */ + extern bool _use_threaded_modal_progress; // From progress.cpp + _use_threaded_modal_progress = false; + } GenerateWorld(GWM_EMPTY, 64, 64); // Make the viewport initialization happy WaitTillGeneratedWorld(); |