mirror of https://github.com/PentHertz/srsLTE.git
add helper method to obtain thread name
this is helpful to, for example, print the name of the thread that calls a function, i.e.: log.console("%s from %s\n", __PRETTY_FUNCTION__, thread::get_name().c_str());
This commit is contained in:
parent
fd01c44d4e
commit
626259eede
|
@ -75,6 +75,17 @@ public:
|
|||
pthread_cancel(_thread);
|
||||
}
|
||||
|
||||
static std::string get_name()
|
||||
{
|
||||
const uint32_t MAX_LEN = 16;
|
||||
char name[MAX_LEN] = {};
|
||||
const pthread_t tid = pthread_self();
|
||||
if (pthread_getname_np(tid, name, MAX_LEN)) {
|
||||
perror("Could not get pthread name");
|
||||
}
|
||||
return std::string(name);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void run_thread() = 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue