Merge branches 'crashlog_improvements', 'save_ext' into jgrpp

# Conflicts:
#	Makefile.src.in
#	projects/openttd_vs140.vcxproj
#	projects/openttd_vs140.vcxproj.filters
#	projects/openttd_vs141.vcxproj
#	projects/openttd_vs141.vcxproj.filters
#	projects/openttd_vs142.vcxproj
#	projects/openttd_vs142.vcxproj.filters
#	src/core/smallstack_type.hpp
#	src/linkgraph/linkgraphjob.cpp
#	src/linkgraph/linkgraphjob.h
#	src/misc.cpp
#	src/network/network_udp.cpp
#	src/openttd.cpp
#	src/saveload/saveload.cpp
This commit is contained in:
Jonathan G Rennison
2019-04-09 19:06:26 +01:00
60 changed files with 541 additions and 1236 deletions

View File

@@ -12,7 +12,7 @@
#ifndef LINKGRAPHJOB_H
#define LINKGRAPHJOB_H
#include "../thread/thread.h"
#include "../thread.h"
#include "../core/dyn_arena_alloc.hpp"
#include "linkgraph.h"
#include <vector>

View File

@@ -142,13 +142,11 @@ void LinkGraphSchedule::JoinNext()
}
/**
* Run all handlers for the given Job. This method is tailored to
* ThreadObject::New.
* @param j Pointer to a link graph job.
* Run all handlers for the given Job.
* @param job Pointer to a link graph job.
*/
/* static */ void LinkGraphSchedule::Run(void *j)
/* static */ void LinkGraphSchedule::Run(LinkGraphJob *job)
{
LinkGraphJob *job = (LinkGraphJob *)j;
for (uint i = 0; i < lengthof(instance.handlers); ++i) {
if (job->IsJobAborted()) return;
instance.handlers[i]->Run(*job);
@@ -232,20 +230,17 @@ LinkGraphSchedule::~LinkGraphSchedule()
LinkGraphJobGroup::LinkGraphJobGroup(constructor_token token, std::vector<LinkGraphJob *> jobs) :
jobs(std::move(jobs)) { }
void LinkGraphJobGroup::SpawnThread() {
ThreadObject *t = nullptr;
void LinkGraphJobGroup::SpawnThread()
{
/**
* Spawn a thread if possible and run the link graph job in the thread. If
* that's not possible run the job right now in the current thread.
*/
if (ThreadObject::New(&(LinkGraphJobGroup::Run), this, &t, "ottd:linkgraph")) {
this->thread.reset(t);
if (StartNewThread(&this->thread, "ottd:linkgraph", &(LinkGraphJobGroup::Run), this)) {
for (auto &it : this->jobs) {
it->SetJobGroup(this->shared_from_this());
}
} else {
this->thread.reset();
/* Of course this will hang a bit.
* On the other hand, if you want to play games which make this hang noticably
* on a platform without threads then you'll probably get other problems first.
@@ -257,10 +252,11 @@ void LinkGraphJobGroup::SpawnThread() {
}
}
void LinkGraphJobGroup::JoinThread() {
if (!this->thread || this->joined_thread) return;
this->thread->Join();
this->joined_thread = true;
void LinkGraphJobGroup::JoinThread()
{
if (this->thread.joinable()) {
this->thread.join();
}
}
/**

View File

@@ -12,7 +12,7 @@
#ifndef LINKGRAPHSCHEDULE_H
#define LINKGRAPHSCHEDULE_H
#include "../thread/thread.h"
#include "../thread.h"
#include "linkgraph.h"
#include <memory>
@@ -55,7 +55,7 @@ public:
static const uint SPAWN_JOIN_TICK = 21; ///< Tick when jobs are spawned or joined every day.
static LinkGraphSchedule instance;
static void Run(void *j);
static void Run(LinkGraphJob *job);
static void Clear();
void SpawnNext();
@@ -85,8 +85,7 @@ class LinkGraphJobGroup : public std::enable_shared_from_this<LinkGraphJobGroup>
friend LinkGraphJob;
private:
bool joined_thread = false; ///< True if thread has already been joined
std::unique_ptr<ThreadObject> thread; ///< Thread the job group is running in or NULL if it's running in the main thread.
std::thread thread; ///< Thread the job group is running in or NULL if it's running in the main thread.
const std::vector<LinkGraphJob *> jobs; ///< The set of jobs in this job set
private: