Use the event loop name instead of thread name for AOS_LOG
This kills 2 birds with 1 stone.
1) A simulated event loop should print out the name of each event
loop, not the program name.
2) prctl(PR_GET_NAME, thread_name_array) can require higher privileges
sometimes, and is un-necesary for simulations. See 1)
Change-Id: I48731b1cabe34ec66a97f27ee720ba3081da4e94
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/aos/logging/context.cc b/aos/logging/context.cc
index b0fd32e..30d275b 100644
--- a/aos/logging/context.cc
+++ b/aos/logging/context.cc
@@ -78,13 +78,23 @@
// Used in aos/linux_code/init.cc when a thread's name is changed.
void ReloadThreadName() {
if (my_context.created()) {
+ my_context->ClearName();
+ }
+}
+
+void Context::ClearName() { name_size = std::numeric_limits<size_t>::max(); }
+
+std::string_view Context::MyName() {
+ if (name_size == std::numeric_limits<size_t>::max()) {
::std::string my_name = GetMyName();
if (my_name.size() + 1 > sizeof(Context::name)) {
Die("logging: process/thread name '%s' is too long\n", my_name.c_str());
}
- strcpy(my_context->name, my_name.c_str());
- my_context->name_size = my_name.size();
+ strcpy(name, my_name.c_str());
+ name_size = my_name.size();
}
+
+ return std::string_view(&name[0], name_size);
}
Context *Context::Get() {
@@ -94,7 +104,7 @@
}
if (__builtin_expect(!my_context.created(), false)) {
my_context.Create();
- ReloadThreadName();
+ my_context->ClearName();
my_context->source = getpid();
}
return my_context.get();