summaryrefslogtreecommitdiff
path: root/src/newgrf_config.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2019-03-11 00:45:39 +0100
committerMichael Lutz <michi@icosahedron.de>2019-04-06 11:27:39 +0200
commit05f4e7360886e36b221ef5c3af4426625a3de686 (patch)
tree27aed9756e80eca86ff95f5805901a80048b0fb1 /src/newgrf_config.cpp
parent3b86f54fc739510277f434c68e17a93ab6448ed4 (diff)
downloadopenttd-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/newgrf_config.cpp')
-rw-r--r--src/newgrf_config.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index e346a4a82..feb23648a 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -21,6 +21,7 @@
#include "video/video_driver.hpp"
#include "strings_func.h"
#include "textfile_gui.h"
+#include "thread/thread.h"
#include "fileio_func.h"
#include "fios.h"
@@ -682,18 +683,18 @@ bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const
this->num_scanned++;
if (this->next_update <= _realtime_tick) {
- _modal_progress_work_mutex->EndCritical();
- _modal_progress_paint_mutex->BeginCritical();
+ _modal_progress_work_mutex.unlock();
+ _modal_progress_paint_mutex.lock();
const char *name = NULL;
if (c->name != NULL) name = GetGRFStringFromGRFText(c->name->text);
if (name == NULL) name = c->filename;
UpdateNewGRFScanStatus(this->num_scanned, name);
- _modal_progress_work_mutex->BeginCritical();
- _modal_progress_paint_mutex->EndCritical();
+ _modal_progress_work_mutex.lock();
+ _modal_progress_paint_mutex.unlock();
- this->next_update = _realtime_tick + 200;
+ this->next_update = _realtime_tick + MODAL_PROGRESS_REDRAW_TIMEOUT;
}
if (!added) {
@@ -725,7 +726,7 @@ static int CDECL GRFSorter(GRFConfig * const *p1, GRFConfig * const *p2)
*/
void DoScanNewGRFFiles(void *callback)
{
- _modal_progress_work_mutex->BeginCritical();
+ std::unique_lock<std::mutex> lock_work(_modal_progress_work_mutex);
ClearGRFConfigList(&_all_grfs);
TarScanner::DoScan(TarScanner::NEWGRF);
@@ -760,8 +761,8 @@ void DoScanNewGRFFiles(void *callback)
NetworkAfterNewGRFScan();
}
- _modal_progress_work_mutex->EndCritical();
- _modal_progress_paint_mutex->BeginCritical();
+ lock_work.unlock();
+ std::lock_guard<std::mutex> lock_paint(_modal_progress_paint_mutex);
/* Yes... these are the NewGRF windows */
InvalidateWindowClassesData(WC_SAVELOAD, 0, true);
@@ -771,7 +772,6 @@ void DoScanNewGRFFiles(void *callback)
DeleteWindowByClass(WC_MODAL_PROGRESS);
SetModalProgress(false);
MarkWholeScreenDirty();
- _modal_progress_paint_mutex->EndCritical();
}
/**
@@ -785,12 +785,12 @@ void ScanNewGRFFiles(NewGRFScanCallback *callback)
/* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */
MarkWholeScreenDirty();
- if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL, "ottd:newgrf-scan")) {
- _modal_progress_work_mutex->EndCritical();
- _modal_progress_paint_mutex->EndCritical();
+ if (!UseThreadedModelProgress() || !VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL, "ottd:newgrf-scan")) {
+ _modal_progress_work_mutex.unlock();
+ _modal_progress_paint_mutex.unlock();
DoScanNewGRFFiles(callback);
- _modal_progress_paint_mutex->BeginCritical();
- _modal_progress_work_mutex->BeginCritical();
+ _modal_progress_paint_mutex.lock();
+ _modal_progress_work_mutex.lock();
} else {
UpdateNewGRFScanStatus(0, NULL);
}