Go to the documentation of this file.00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #pragma once
00029
00030 #include <thread>
00031 #include <cstdio>
00032 #include <sstream>
00033 #include <cstdarg>
00034 #include <pthread.h>
00035
00036 namespace mavutils {
00037
00047 inline bool set_thread_name(std::thread &thd, const char *name, ...)
00048 {
00049 pthread_t pth = thd.native_handle();
00050 va_list arg_list;
00051 va_start(arg_list, name);
00052
00053 char new_name[256];
00054 vsnprintf(new_name, sizeof(new_name), name, arg_list);
00055 va_end(arg_list);
00056 return pthread_setname_np(pth, new_name) == 0;
00057 }
00058
00062 template <typename Thread>
00063 inline bool set_thread_name(Thread &thd, std::string &name)
00064 {
00065 return set_thread_name(thd, name.c_str());
00066 };
00067
00071 template <typename T>
00072 inline const char *to_string_cs(T &obj)
00073 {
00074 std::ostringstream ss;
00075 ss << obj;
00076 return ss.str().c_str();
00077 }
00078
00079 };