-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathThreadUtils.cpp
More file actions
54 lines (46 loc) · 1.29 KB
/
ThreadUtils.cpp
File metadata and controls
54 lines (46 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "Base.h"
#include "ThreadUtils.h"
#include <sstream>
#ifndef _WIN32
#include <pthread.h>
#endif
NS_BEGIN
size_t OpaqueThreadIdToThreadId(const std::thread::id &id);
#ifndef _WIN32
size_t OpaqueThreadIdToThreadId(const pthread_t &id);
#endif
//#################################################################################################
size_t GetThreadId(const std::thread::id &id)
{
size_t nThreadId = 0;
if(id == std::thread::id())
{ // Get current thread Id
#ifdef _WIN32
nThreadId = GetCurrentThreadId();
#else
nThreadId = OpaqueThreadIdToThreadId(pthread_self());
#endif
}
else
{ // Get Id for provided thread
nThreadId = OpaqueThreadIdToThreadId(id);
}
return nThreadId;
}
//#################################################################################################
size_t OpaqueThreadIdToThreadId(const std::thread::id &id)
{
std::ostringstream stream;
stream << id;
return StringToInteger8<size_t>(stream.str().c_str());
}
#ifndef _WIN32
//#################################################################################################
size_t OpaqueThreadIdToThreadId(const pthread_t &id)
{
std::ostringstream stream;
stream << id;
return StringToInteger8<size_t>(stream.str().c_str());
}
#endif
NS_END