From 80a4aef60e12568580473b124093bc4f520bd4c2 Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Sat, 28 Sep 2024 04:57:38 +0800 Subject: [PATCH] Utility function to recover the hex address of the parameter thread. --- include/util/ThreadId.hpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 include/util/ThreadId.hpp diff --git a/include/util/ThreadId.hpp b/include/util/ThreadId.hpp new file mode 100644 index 0000000..7cfe860 --- /dev/null +++ b/include/util/ThreadId.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 - Nathanne Isip + * This file is part of Zhivo. + * + * Zhivo is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * Zhivo is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Zhivo. If not, see . + */ + +#ifndef ZHIVO_UTIL_THREAD_ID_HPP +#define ZHIVO_UTIL_THREAD_ID_HPP + +#include +#include +#include + +namespace ZhivoUtil { + +inline static std::string getThreadId(std::thread::id id) { + std::ostringstream oss; + oss << "0x" << std::hex << id; + + return oss.str(); +} + +}; + +#endif