summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/genworld.cpp2
-rw-r--r--src/linkgraph/linkgraphjob.cpp2
-rw-r--r--src/network/core/tcp_connect.cpp2
-rw-r--r--src/network/network_udp.cpp6
-rw-r--r--src/newgrf_config.cpp2
-rw-r--r--src/saveload/saveload.cpp2
-rw-r--r--src/thread/thread.h3
-rw-r--r--src/thread/thread_morphos.cpp2
-rw-r--r--src/thread/thread_none.cpp2
-rw-r--r--src/thread/thread_os2.cpp2
-rw-r--r--src/thread/thread_pthread.cpp20
-rw-r--r--src/thread/thread_win32.cpp2
-rw-r--r--src/video/sdl_v.cpp2
13 files changed, 30 insertions, 19 deletions
diff --git a/src/genworld.cpp b/src/genworld.cpp
index a08b32311..5cdb129b9 100644
--- a/src/genworld.cpp
+++ b/src/genworld.cpp
@@ -331,7 +331,7 @@ 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)) {
+ if (!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();
diff --git a/src/linkgraph/linkgraphjob.cpp b/src/linkgraph/linkgraphjob.cpp
index 20cbf3f64..537303cf3 100644
--- a/src/linkgraph/linkgraphjob.cpp
+++ b/src/linkgraph/linkgraphjob.cpp
@@ -61,7 +61,7 @@ void LinkGraphJob::EraseFlows(NodeID from)
*/
void LinkGraphJob::SpawnThread()
{
- if (!ThreadObject::New(&(LinkGraphSchedule::Run), this, &this->thread)) {
+ if (!ThreadObject::New(&(LinkGraphSchedule::Run), this, &this->thread, "ottd:linkgraph")) {
this->thread = NULL;
/* Of course this will hang a bit.
* On the other hand, if you want to play games which make this hang noticably
diff --git a/src/network/core/tcp_connect.cpp b/src/network/core/tcp_connect.cpp
index ccbf93f3c..2dc789882 100644
--- a/src/network/core/tcp_connect.cpp
+++ b/src/network/core/tcp_connect.cpp
@@ -35,7 +35,7 @@ TCPConnecter::TCPConnecter(const NetworkAddress &address) :
address(address)
{
*_tcp_connecters.Append() = this;
- if (!ThreadObject::New(TCPConnecter::ThreadEntry, this, &this->thread)) {
+ if (!ThreadObject::New(TCPConnecter::ThreadEntry, this, &this->thread, "ottd:tcp")) {
this->Connect();
}
}
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index 1cccbf644..1dc696065 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -109,7 +109,7 @@ static void NetworkUDPQueryServerThread(void *pntr)
void NetworkUDPQueryServer(NetworkAddress address, bool manually)
{
NetworkUDPQueryServerInfo *info = new NetworkUDPQueryServerInfo(address, manually);
- if (address.IsResolved() || !ThreadObject::New(NetworkUDPQueryServerThread, info)) {
+ if (address.IsResolved() || !ThreadObject::New(NetworkUDPQueryServerThread, info, NULL, "ottd:udp-query")) {
NetworkUDPQueryServerThread(info);
}
}
@@ -565,7 +565,7 @@ void NetworkUDPRemoveAdvertise(bool blocking)
/* Check if we are advertising */
if (!_networking || !_network_server || !_network_udp_server) return;
- if (blocking || !ThreadObject::New(NetworkUDPRemoveAdvertiseThread, NULL)) {
+ if (blocking || !ThreadObject::New(NetworkUDPRemoveAdvertiseThread, NULL, NULL, "ottd:udp-advert")) {
NetworkUDPRemoveAdvertiseThread(NULL);
}
}
@@ -648,7 +648,7 @@ void NetworkUDPAdvertise()
if (_next_advertisement < _last_advertisement) _next_advertisement = UINT32_MAX;
if (_next_retry < _last_advertisement) _next_retry = UINT32_MAX;
- if (!ThreadObject::New(NetworkUDPAdvertiseThread, NULL)) {
+ if (!ThreadObject::New(NetworkUDPAdvertiseThread, NULL, NULL, "ottd:udp-advert")) {
NetworkUDPAdvertiseThread(NULL);
}
}
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index bd95373d9..19ac4d4a7 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -786,7 +786,7 @@ 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)) {
+ if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL, "ottd:newgrf-scan")) {
_modal_progress_work_mutex->EndCritical();
_modal_progress_paint_mutex->EndCritical();
DoScanNewGRFFiles(callback);
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 7b7341115..87df2c3a6 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -2585,7 +2585,7 @@ static SaveOrLoadResult DoSave(SaveFilter *writer, bool threaded)
SlSaveChunks();
SaveFileStart();
- if (!threaded || !ThreadObject::New(&SaveFileToDiskThread, NULL, &_save_thread)) {
+ if (!threaded || !ThreadObject::New(&SaveFileToDiskThread, NULL, &_save_thread, "ottd:savegame")) {
if (threaded) DEBUG(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode...");
SaveOrLoadResult result = SaveFileToDisk(false);
diff --git a/src/thread/thread.h b/src/thread/thread.h
index b944a53b9..07831bb4b 100644
--- a/src/thread/thread.h
+++ b/src/thread/thread.h
@@ -44,9 +44,10 @@ public:
* @param proc The procedure to call inside the thread.
* @param param The params to give with 'proc'.
* @param thread Place to store a pointer to the thread in. May be NULL.
+ * @param name A name for the thread. May be NULL.
* @return True if the thread was started correctly.
*/
- static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread = NULL);
+ static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread = NULL, const char *name = NULL);
};
/**
diff --git a/src/thread/thread_morphos.cpp b/src/thread/thread_morphos.cpp
index cc6b2f9d3..6d00d0579 100644
--- a/src/thread/thread_morphos.cpp
+++ b/src/thread/thread_morphos.cpp
@@ -193,7 +193,7 @@ private:
}
};
-/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
+/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread, const char *name)
{
ThreadObject *to = new ThreadObject_MorphOS(proc, param, thread == NULL);
if (thread != NULL) *thread = to;
diff --git a/src/thread/thread_none.cpp b/src/thread/thread_none.cpp
index afa799b23..91eb50b11 100644
--- a/src/thread/thread_none.cpp
+++ b/src/thread/thread_none.cpp
@@ -14,7 +14,7 @@
#include "../safeguards.h"
-/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
+/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread, const char *name)
{
if (thread != NULL) *thread = NULL;
return false;
diff --git a/src/thread/thread_os2.cpp b/src/thread/thread_os2.cpp
index 2dcb8288f..c66e2ad64 100644
--- a/src/thread/thread_os2.cpp
+++ b/src/thread/thread_os2.cpp
@@ -83,7 +83,7 @@ private:
}
};
-/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
+/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread, const char *name)
{
ThreadObject *to = new ThreadObject_OS2(proc, param, thread == NULL);
if (thread != NULL) *thread = to;
diff --git a/src/thread/thread_pthread.cpp b/src/thread/thread_pthread.cpp
index ce407fd94..747b8943d 100644
--- a/src/thread/thread_pthread.cpp
+++ b/src/thread/thread_pthread.cpp
@@ -25,16 +25,18 @@ private:
OTTDThreadFunc proc; ///< External thread procedure.
void *param; ///< Parameter for the external thread procedure.
bool self_destruct; ///< Free ourselves when done?
+ const char *name; ///< Name for the thread
public:
/**
* Create a pthread and start it, calling proc(param).
*/
- ThreadObject_pthread(OTTDThreadFunc proc, void *param, bool self_destruct) :
+ ThreadObject_pthread(OTTDThreadFunc proc, void *param, bool self_destruct, const char *name) :
thread(0),
proc(proc),
param(param),
- self_destruct(self_destruct)
+ self_destruct(self_destruct),
+ name(name)
{
pthread_create(&this->thread, NULL, &stThreadProc, this);
}
@@ -60,7 +62,15 @@ private:
*/
static void *stThreadProc(void *thr)
{
- ((ThreadObject_pthread *)thr)->ThreadProc();
+ ThreadObject_pthread *self = (ThreadObject_pthread *) thr;
+#if defined(__GLIBC__)
+#if __GLIBC_PREREQ(2, 12)
+ if (self->name) {
+ pthread_setname_np(pthread_self(), self->name);
+ }
+#endif
+#endif
+ self->ThreadProc();
pthread_exit(NULL);
}
@@ -85,9 +95,9 @@ private:
}
};
-/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
+/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread, const char *name)
{
- ThreadObject *to = new ThreadObject_pthread(proc, param, thread == NULL);
+ ThreadObject *to = new ThreadObject_pthread(proc, param, thread == NULL, name);
if (thread != NULL) *thread = to;
return true;
}
diff --git a/src/thread/thread_win32.cpp b/src/thread/thread_win32.cpp
index c37baf7c3..81a721253 100644
--- a/src/thread/thread_win32.cpp
+++ b/src/thread/thread_win32.cpp
@@ -96,7 +96,7 @@ private:
}
};
-/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
+/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread, const char *name)
{
ThreadObject *to = new ThreadObject_Win32(proc, param, thread == NULL);
if (thread != NULL) *thread = to;
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index ea68c2165..4ee96db77 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -687,7 +687,7 @@ void VideoDriver_SDL::MainLoop()
_draw_mutex->BeginCritical();
_draw_continue = true;
- _draw_threaded = ThreadObject::New(&DrawSurfaceToScreenThread, NULL, &_draw_thread);
+ _draw_threaded = ThreadObject::New(&DrawSurfaceToScreenThread, NULL, &_draw_thread, "ottd:draw-sdl");
/* Free the mutex if we won't be able to use it. */
if (!_draw_threaded) {