| Index: base/threading/platform_thread.h
|
| diff --git a/base/threading/platform_thread.h b/base/threading/platform_thread.h
|
| index f2f3b260586cdcf67a75fae4b0a3e0119ece61f6..28743145610c70fe14f8c8fdd1e377a9aa861528 100644
|
| --- a/base/threading/platform_thread.h
|
| +++ b/base/threading/platform_thread.h
|
| @@ -23,12 +23,48 @@
|
|
|
| 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.
|
| +// 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 cannot be reliably used
|
| +// to distinguish a new thread from an old, dead thread.
|
| +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 +137,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();
|
|
|
|
|