name our threads for ease of debugging
Change-Id: If35518ed5f33aa38cc054d075cbe2850960ea3f5
diff --git a/aos/linux_code/logging/linux_interface.cc b/aos/linux_code/logging/linux_interface.cc
index 0040e94..4e8317b 100644
--- a/aos/linux_code/logging/linux_interface.cc
+++ b/aos/linux_code/logging/linux_interface.cc
@@ -11,7 +11,8 @@
namespace internal {
namespace {
-// TODO(brians): Differentiate between threads in the same process.
+// TODO(brians): Differentiate between threads with the same name in the same
+// process.
::std::string GetMyName() {
// The maximum number of characters that can make up a thread name.
@@ -50,6 +51,17 @@
} // namespace
+// Used in aos/linux_code/init.cc when a thread's name is changed.
+void ReloadThreadName() {
+ if (my_context.created()) {
+ my_context->name = GetMyName();
+ if (my_context->name.size() + 1 > sizeof(LogMessage::name)) {
+ Die("logging: process/thread name '%s' is too long\n",
+ my_context->name.c_str());
+ }
+ }
+}
+
Context *Context::Get() {
if (__builtin_expect(delete_current_context, false)) {
my_context.Clear();
@@ -58,10 +70,7 @@
if (__builtin_expect(!my_context.created(), false)) {
my_context.Create();
my_context->name = GetMyName();
- if (my_context->name.size() + 1 > sizeof(LogMessage::name)) {
- Die("logging: process/thread name '%s' is too long\n",
- my_context->name.c_str());
- }
+ ReloadThreadName();
my_context->source = getpid();
}
return my_context.get();