Chromium Code Reviews| Index: base/threading/platform_thread.h |
| diff --git a/base/threading/platform_thread.h b/base/threading/platform_thread.h |
| index f2f3b260586cdcf67a75fae4b0a3e0119ece61f6..a983d70381ec787339348b1ac997b27a45885900 100644 |
| --- a/base/threading/platform_thread.h |
| +++ b/base/threading/platform_thread.h |
| @@ -23,12 +23,42 @@ |
| namespace base { |
| +// Used for logging. Always an integer value. |
| #if defined(OS_WIN) |
| typedef DWORD PlatformThreadId; |
| #elif defined(OS_POSIX) |
| typedef pid_t PlatformThreadId; |
| #endif |
| +// Used for thread checking and debugging. |
| +// Meant to be as fast as possible. |
|
Mark Mentovai
2014/05/23 17:55:16
Your comment should say something about the unique
hubbe
2014/05/23 19:31:14
Better?
|
| +class PlatformThreadRef { |
| + public: |
| +#if defined(OS_WIN) |
| + typedef DWORD RefType; |
| +#elif defined(OS_POSIX) |
| + typedef pthread_t RefType; |
| +#endif |
| + PlatformThreadRef() |
| + : id_(0) { |
| + } |
| + |
| + explicit PlatformThreadRef(RefType id) |
| + : id_(id) { |
| + } |
| + |
| + bool operator==(PlatformThreadRef other) const { |
| + return id_ == other.id_; |
| + } |
| + |
| + bool is_null() const { |
| + return id_ == 0; |
| + } |
| + private: |
| + RefType id_; |
| +}; |
| + |
| +// Used to operate on threads. |
| class PlatformThreadHandle { |
| public: |
| #if defined(OS_WIN) |
| @@ -101,6 +131,10 @@ class BASE_EXPORT PlatformThread { |
| // Gets the current thread id, which may be useful for logging purposes. |
| static PlatformThreadId CurrentId(); |
| + // Gets the current thread reference, which can be used to check if |
| + // we're on the right thread quickly. |
| + static PlatformThreadRef CurrentRef(); |
| + |
| // Get the current handle. |
| static PlatformThreadHandle CurrentHandle(); |