Custom formatter for flag 't', new Utils::GetThreadName()

This commit is contained in:
Vladyslav Baranovskyi
2024-05-30 16:30:09 +03:00
parent 2df5706df4
commit 3127af5bc7
4 changed files with 53 additions and 3 deletions

View File

@@ -12,6 +12,9 @@
#include <pthread.h>
#endif
#include <fstream>
#include <string>
#include <locale>
#include <codecvt>
namespace OpenVulkano
{
@@ -28,6 +31,26 @@ namespace OpenVulkano
#endif
}
std::string Utils::GetThreadName()
{
#ifdef _MSC_VER
auto thisThread = ::GetCurrentThread();
PWSTR threadName;
GetThreadDescription(thisThread, &threadName);
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
std::string str = converter.to_bytes(threadName);
LocalFree(threadName);
return str;
#else
// NOTE(vb): Accoring to linux man page size of this array must be _at least_ 16 bytes...
// But I don't know whether is it applicable to have the buffer of bigger size
char threadName[16];
pthread_getname_np(pthread_self(), threadName, sizeof(threadName));
std::string str = threadName;
return str;
#endif
}
Array<char> Utils::ReadFile(const std::string& filePath, bool emptyOnMissing)
{
std::ifstream file(filePath, std::ios::ate | std::ios::binary);