26 #ifndef GOBY_MIDDLEWARE_COMMON_H
27 #define GOBY_MIDDLEWARE_COMMON_H
31 #include <sys/syscall.h>
35 #include <boost/algorithm/string.hpp>
46 const int underscore_pos = 5;
53 inline std::string
thread_id(std::thread::id i = std::this_thread::get_id())
56 ss << std::hex << std::hash<std::thread::id>{}(i);
62 inline uint64_t gettid()
65 pthread_threadid_np(NULL, &tid);
68 #elif defined SYS_gettid
71 return syscall(SYS_gettid);
74 #error "SYS_gettid unavailable on this system, and this is not an Apple system."
80 std::ifstream hs(
"/etc/hostname");
83 std::string
hostname((std::istreambuf_iterator<char>(hs)),
84 std::istreambuf_iterator<char>());
97 static const std::string host_id =
hostname();
99 static const std::string full_pid = host_id + std::string(
"-p") + pid;