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

@@ -206,23 +206,6 @@ bool GetClipboardContents(char *buffer, const char *last)
}
#endif
uint GetCPUCoreCount()
{
uint count = 1;
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
if (MacOSVersionIsAtLeast(10, 5, 0)) {
count = (uint)[ [ NSProcessInfo processInfo ] activeProcessorCount ];
} else
#endif
{
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
count = MPProcessorsScheduled();
#endif
}
return count;
}
/**
* Check if a font is a monospace font.
* @param name Name of the font.

View File

@@ -18,6 +18,7 @@
#include "../../core/random_func.hpp"
#include "../../string_func.h"
#include "../../textbuf_gui.h"
#include "../../thread.h"
#include "table/strings.h"
@@ -204,25 +205,22 @@ bool GetClipboardContents(char *buffer, const char *last)
}
void CSleep(int milliseconds)
{
#ifndef __INNOTEK_LIBC__
delay(milliseconds);
#else
usleep(milliseconds * 1000);
#endif
}
const char *FS2OTTD(const char *name) {return name;}
const char *OTTD2FS(const char *name) {return name;}
uint GetCPUCoreCount()
{
return 1;
}
void OSOpenBrowser(const char *url)
{
// stub only
DEBUG(misc, 0, "Failed to open url: %s", url);
}
void SetCurrentThreadName(const char *)
{
}
int GetCurrentThreadName(char *str, const char *last) { return 0; }
void SetSelfAsMainThread() { }
bool IsMainThread() { return false; }
bool IsNonMainThread() { return false; }

View File

@@ -17,6 +17,7 @@
#include "../../debug.h"
#include "../../string_func.h"
#include "../../fios.h"
#include "../../thread.h"
#include <dirent.h>
@@ -43,11 +44,17 @@
#include <sys/sysctl.h>
#endif
#ifndef NO_THREADS
#include <pthread.h>
#endif
#if defined(__APPLE__)
#if defined(WITH_SDL)
# if defined(WITH_SDL)
/* the mac implementation needs this file included in the same file as main() */
#include <SDL.h>
#endif
# include <SDL.h>
# endif
# include "../macosx/macos.h"
#endif
#include "../../safeguards.h"
@@ -266,44 +273,7 @@ bool GetClipboardContents(char *buffer, const char *last)
#endif
/* multi os compatible sleep function */
void CSleep(int milliseconds)
{
usleep(milliseconds * 1000);
}
#ifndef __APPLE__
uint GetCPUCoreCount()
{
uint count = 1;
#ifdef HAS_SYSCTL
int ncpu = 0;
size_t len = sizeof(ncpu);
#ifdef OPENBSD
int name[2];
name[0] = CTL_HW;
name[1] = HW_NCPU;
if (sysctl(name, 2, &ncpu, &len, NULL, 0) < 0) {
ncpu = 0;
}
#else
if (sysctlbyname("hw.availcpu", &ncpu, &len, NULL, 0) < 0) {
sysctlbyname("hw.ncpu", &ncpu, &len, NULL, 0);
}
#endif /* #ifdef OPENBSD */
if (ncpu > 0) count = ncpu;
#elif defined(_SC_NPROCESSORS_ONLN)
long res = sysconf(_SC_NPROCESSORS_ONLN);
if (res > 0) count = res;
#endif
return count;
}
void OSOpenBrowser(const char *url)
{
pid_t child_pid = fork();
@@ -317,4 +287,56 @@ void OSOpenBrowser(const char *url)
DEBUG(misc, 0, "Failed to open url: %s", url);
exit(0);
}
#endif /* __APPLE__ */
void SetCurrentThreadName(const char *threadName) {
#if !defined(NO_THREADS) && defined(__GLIBC__)
#if __GLIBC_PREREQ(2, 12)
if (threadName) pthread_setname_np(pthread_self(), threadName);
#endif /* __GLIBC_PREREQ(2, 12) */
#endif /* !defined(NO_THREADS) && defined(__GLIBC__) */
#if defined(__APPLE__)
MacOSSetThreadName(threadName);
#endif /* defined(__APPLE__) */
}
int GetCurrentThreadName(char *str, const char *last)
{
#if !defined(NO_THREADS) && defined(__GLIBC__)
#if __GLIBC_PREREQ(2, 12)
char buffer[16];
int result = pthread_getname_np(pthread_self(), buffer, sizeof(buffer));
if (result == 0) {
return seprintf(str, last, "%s", buffer);
}
#endif
#endif
return 0;
}
static pthread_t main_thread;
void SetSelfAsMainThread()
{
#if !defined(NO_THREADS)
main_thread = pthread_self();
#endif
}
bool IsMainThread()
{
#if !defined(NO_THREADS)
return main_thread == pthread_self();
#else
return true;
#endif
}
bool IsNonMainThread()
{
#if !defined(NO_THREADS)
return main_thread != pthread_self();
#else
return false;
#endif
}

View File

@@ -30,6 +30,7 @@
#include <errno.h>
#include <sys/stat.h>
#include "../../language.h"
#include "../../thread.h"
#include "../../safeguards.h"
@@ -81,7 +82,7 @@ void ShowOSErrorBox(const char *buf, bool system)
{
_in_event_loop_post_crash = true;
MyShowCursor(true);
MessageBox(GetActiveWindow(), OTTD2FS(buf), _T("Error!"), MB_ICONSTOP);
MessageBox(GetActiveWindow(), OTTD2FS(buf), _T("Error!"), MB_ICONSTOP | MB_TASKMODAL);
}
void OSOpenBrowser(const char *url)
@@ -546,12 +547,6 @@ bool GetClipboardContents(char *buffer, const char *last)
}
void CSleep(int milliseconds)
{
Sleep(milliseconds);
}
/**
* Convert to OpenTTD's encoding from that of the local environment.
* When the project is built in UNICODE, the system codepage is irrelevant and
@@ -733,14 +728,6 @@ const char *GetCurrentLocale(const char *)
return retbuf;
}
uint GetCPUCoreCount()
{
SYSTEM_INFO info;
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
}
static WCHAR _cur_iso_locale[16] = L"";
@@ -805,6 +792,42 @@ int OTTDStringCompare(const char *s1, const char *s2)
return CompareString(MAKELCID(_current_language->winlangid, SORT_DEFAULT), NORM_IGNORECASE, s1_buf, -1, s2_buf, -1);
}
static DWORD main_thread_id;
void SetSelfAsMainThread()
{
main_thread_id = GetCurrentThreadId();
}
bool IsMainThread()
{
return main_thread_id == GetCurrentThreadId();
}
bool IsNonMainThread()
{
return main_thread_id != GetCurrentThreadId();
}
static std::map<DWORD, std::string> _thread_name_map;
static std::mutex _thread_name_map_mutex;
static void Win32SetThreadName(uint id, const char *name)
{
std::lock_guard<std::mutex> lock(_thread_name_map_mutex);
_thread_name_map[id] = name;
}
int GetCurrentThreadName(char *str, const char *last)
{
std::lock_guard<std::mutex> lock(_thread_name_map_mutex);
auto iter = _thread_name_map.find(GetCurrentThreadId());
if (iter != _thread_name_map.end()) {
return seprintf(str, last, "%s", iter->second.c_str());
}
return 0;
}
#ifdef _MSC_VER
/* Based on code from MSDN: https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx */
const DWORD MS_VC_EXCEPTION = 0x406D1388;
@@ -819,12 +842,14 @@ PACK_N(struct THREADNAME_INFO {
/**
* Signal thread name to any attached debuggers.
*/
void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
void SetCurrentThreadName(const char *threadName)
{
Win32SetThreadName(GetCurrentThreadId(), threadName);
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = threadName;
info.dwThreadID = dwThreadID;
info.dwThreadID = -1;
info.dwFlags = 0;
#pragma warning(push)
@@ -835,4 +860,9 @@ void SetWin32ThreadName(DWORD dwThreadID, const char* threadName)
}
#pragma warning(pop)
}
#else
void SetCurrentThreadName(const char *)
{
Win32SetThreadName(GetCurrentThreadId(), threadName);
}
#endif

View File

@@ -39,12 +39,6 @@ HRESULT OTTDSHGetFolderPath(HWND, int, HANDLE, DWORD, LPTSTR);
#define SHGFP_TYPE_CURRENT 0
#endif /* __MINGW32__ */
#ifdef _MSC_VER
void SetWin32ThreadName(DWORD dwThreadID, const char* threadName);
#else
static inline void SetWin32ThreadName(DWORD dwThreadID, const char* threadName) {}
#endif
void Win32SetCurrentLocaleName(const char *iso_code);
int OTTDStringCompare(const char *s1, const char *s2);