MCPcopy Create free account
hub / github.com/apache/brpc / PlatformThreadRef

Class PlatformThreadRef

src/butil/threading/platform_thread.h:41–65  ·  view source on GitHub ↗

Used for thread checking and debugging. Meant to be as fast as possible. These are produced by PlatformThread::CurrentRef(), and used to later check if we are on the same thread or not by using ==. These are safe to copy between threads, but can't be copied to another process as they have no meaning there. Also, the internal identifier can be re-used after a thread dies, so a PlatformThreadRef can

Source from the content-addressed store, hash-verified

39// after a thread dies, so a PlatformThreadRef cannot be reliably used
40// to distinguish a new thread from an old, dead thread.
41class PlatformThreadRef {
42 public:
43#if defined(OS_WIN)
44 typedef DWORD RefType;
45#elif defined(OS_POSIX)
46 typedef pthread_t RefType;
47#endif
48 PlatformThreadRef()
49 : id_(0) {
50 }
51
52 explicit PlatformThreadRef(RefType id)
53 : id_(id) {
54 }
55
56 bool operator==(PlatformThreadRef other) const {
57 return id_ == other.id_;
58 }
59
60 bool is_null() const {
61 return id_ == 0;
62 }
63 private:
64 RefType id_;
65};
66
67// Used to operate on threads.
68class PlatformThreadHandle {

Callers 2

CurrentRefMethod · 0.85
DetachFromThreadMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected