aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorGiel van Schijndel <me@mortis.eu>2012-06-24 17:03:57 +0200
committerGiel van Schijndel <me@mortis.eu>2012-07-17 01:50:35 +0200
commit96931d6f78ccc21ec38cd4655b1a250893a6f252 (patch)
treea7bd6c9bb2d0a9378b6db894b470126d0c2b4221 /src/util.cpp
parent1c009d622ded6dd254d6be5161b4df875d492d12 (diff)
Give threads a recognisable name to aid in debugging
NOTE: These thread names are visible in gdb when using 'info threads'. Additionally both 'top' and 'ps' show these names *unless* told to display the command-line instead of task name. Signed-off-by: Giel van Schijndel <me@mortis.eu>
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 9881545a02..56755a25bc 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -51,6 +51,8 @@ namespace boost {
#endif
#include <io.h> /* for _commit */
#include "shlobj.h"
+#elif defined(__linux__)
+# include <sys/prctl.h>
#endif
using namespace std;
@@ -1275,3 +1277,13 @@ void runCommand(std::string strCommand)
printf("runCommand error: system(%s) returned %d\n", strCommand.c_str(), nErr);
}
+void RenameThread(const char* name)
+{
+#if defined(__linux__) && defined(PR_SET_NAME)
+ // Only the first 15 characters are used (16 - NUL terminator)
+ ::prctl(PR_SET_NAME, name, 0, 0, 0);
+#else
+ // Prevent warnings for unused parameters...
+ (void)name;
+#endif
+}