diff options
Diffstat (limited to 'src/genworld.cpp')
-rw-r--r-- | src/genworld.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/genworld.cpp b/src/genworld.cpp index 25d6a7bd9..64caf3b89 100644 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -34,6 +34,7 @@ #include "game/game.hpp" #include "game/game_instance.hpp" #include "string_func.h" +#include "thread/thread.h" #include "safeguards.h" @@ -98,9 +99,10 @@ static void _GenerateWorld(void *) /* Make sure everything is done via OWNER_NONE. */ Backup<CompanyByte> _cur_company(_current_company, OWNER_NONE, FILE_LINE); + std::unique_lock<std::mutex> lock(_modal_progress_work_mutex, std::defer_lock); try { _generating_world = true; - _modal_progress_work_mutex->BeginCritical(); + lock.lock(); if (_network_dedicated) DEBUG(net, 1, "Generating map, please wait..."); /* Set the Random() seed to generation_seed so we produce the same map with the same seed */ if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = _settings_newgame.game_creation.generation_seed = InteractiveRandom(); @@ -194,7 +196,7 @@ static void _GenerateWorld(void *) IncreaseGeneratingWorldProgress(GWP_GAME_START); CleanupGeneration(); - _modal_progress_work_mutex->EndCritical(); + lock.unlock(); ShowNewGRFError(); @@ -210,7 +212,6 @@ static void _GenerateWorld(void *) BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP, true); if (_cur_company.IsValid()) _cur_company.Restore(); _generating_world = false; - _modal_progress_work_mutex->EndCritical(); throw; } } @@ -243,15 +244,15 @@ void WaitTillGeneratedWorld() { if (_gw.thread == NULL) return; - _modal_progress_work_mutex->EndCritical(); - _modal_progress_paint_mutex->EndCritical(); + _modal_progress_work_mutex.unlock(); + _modal_progress_paint_mutex.unlock(); _gw.quit_thread = true; _gw.thread->Join(); delete _gw.thread; _gw.thread = NULL; _gw.threaded = false; - _modal_progress_work_mutex->BeginCritical(); - _modal_progress_paint_mutex->BeginCritical(); + _modal_progress_work_mutex.lock(); + _modal_progress_paint_mutex.lock(); } /** @@ -331,12 +332,12 @@ void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_setti _gw.thread = NULL; } - if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread, "ottd:genworld")) { + if (!UseThreadedModelProgress() || !VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread, "ottd:genworld")) { DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode"); _gw.threaded = false; - _modal_progress_work_mutex->EndCritical(); + _modal_progress_work_mutex.unlock(); _GenerateWorld(NULL); - _modal_progress_work_mutex->BeginCritical(); + _modal_progress_work_mutex.lock(); return; } |