diff options
author | frosch <frosch@openttd.org> | 2016-10-30 17:29:33 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2016-10-30 17:29:33 +0000 |
commit | 31f046bd9bfec6be5b5a24f113f3b301376763e6 (patch) | |
tree | aa00cd46578f397c91e8238fe9f5a8b462b52b38 /src/thread | |
parent | dd190397d6cf16a731dd05a7f722eb76ad21c01f (diff) | |
download | openttd-31f046bd9bfec6be5b5a24f113f3b301376763e6.tar.xz |
(svn r27670) -Add: [FS#6471] Assign descriptive names to (GNU pthread) threads. (JGR)
Diffstat (limited to 'src/thread')
-rw-r--r-- | src/thread/thread.h | 3 | ||||
-rw-r--r-- | src/thread/thread_morphos.cpp | 2 | ||||
-rw-r--r-- | src/thread/thread_none.cpp | 2 | ||||
-rw-r--r-- | src/thread/thread_os2.cpp | 2 | ||||
-rw-r--r-- | src/thread/thread_pthread.cpp | 20 | ||||
-rw-r--r-- | src/thread/thread_win32.cpp | 2 |
6 files changed, 21 insertions, 10 deletions
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; |