| Index: base/threading/thread_checker.h
|
| diff --git a/base/threading/thread_checker.h b/base/threading/thread_checker.h
|
| index 712b5b56f03efeb429dd9231bfc8807a99c0dc32..b04bb6f7b4f65bb157f9f7e73c3ce3a4d0485f30 100644
|
| --- a/base/threading/thread_checker.h
|
| +++ b/base/threading/thread_checker.h
|
| @@ -6,23 +6,24 @@
|
| #define BASE_THREADING_THREAD_CHECKER_H_
|
| #pragma once
|
|
|
| -#ifndef NDEBUG
|
| #include "base/synchronization/lock.h"
|
| #include "base/threading/platform_thread.h"
|
| -#endif // NDEBUG
|
|
|
| namespace base {
|
|
|
| +class ThreadCheckerImpl;
|
| +class ThreadCheckerDoNothing;
|
| +
|
| // Before using this class, please consider using NonThreadSafe as it
|
| // makes it much easier to determine the nature of your class.
|
| //
|
| -// A helper class used to help verify that some methods of a class are
|
| -// called from the same thread. One can inherit from this class and use
|
| -// CalledOnValidThread() to verify.
|
| +// ThreadChecker is a helper class used to help verify that some methods of a
|
| +// class are called from the same thread. One can inherit from this class and
|
| +// use CalledOnValidThread() to verify.
|
| //
|
| -// Inheriting from class indicates that one must be careful when using the class
|
| -// with multiple threads. However, it is up to the class document to indicate
|
| -// how it can be used with threads.
|
| +// Inheriting from class indicates that one must be careful when using the
|
| +// class with multiple threads. However, it is up to the class document to
|
| +// indicate how it can be used with threads.
|
| //
|
| // Example:
|
| // class MyClass : public ThreadChecker {
|
| @@ -34,12 +35,22 @@ namespace base {
|
| // }
|
| //
|
| // In Release mode, CalledOnValidThread will always return true.
|
| -//
|
| #ifndef NDEBUG
|
| -class ThreadChecker {
|
| +typedef ThreadCheckerImpl ThreadChecker;
|
| +#else
|
| +typedef ThreadCheckerDoNothing ThreadChecker;
|
| +#endif // NDEBUG
|
| +
|
| +// Real implementation, for use in debug mode, or for temporary use
|
| +// in release mode (e.g. to CHECK on a threading issue seen only in
|
| +// the wild).
|
| +//
|
| +// Note: You should almost always use the ThreadChecker typedef to get the
|
| +// right version.
|
| +class ThreadCheckerImpl {
|
| public:
|
| - ThreadChecker();
|
| - ~ThreadChecker();
|
| + ThreadCheckerImpl();
|
| + ~ThreadCheckerImpl();
|
|
|
| bool CalledOnValidThread() const;
|
|
|
| @@ -56,9 +67,12 @@ class ThreadChecker {
|
| // It's guarded by |lock_|.
|
| mutable PlatformThreadId valid_thread_id_;
|
| };
|
| -#else
|
| -// Do nothing in release mode.
|
| -class ThreadChecker {
|
| +
|
| +// Do nothing implementation, for use in release mode.
|
| +//
|
| +// Note: You should almost always use the ThreadChecker typedef to get the
|
| +// right version.
|
| +class ThreadCheckerDoNothing {
|
| public:
|
| bool CalledOnValidThread() const {
|
| return true;
|
| @@ -66,7 +80,6 @@ class ThreadChecker {
|
|
|
| void DetachFromThread() {}
|
| };
|
| -#endif // NDEBUG
|
|
|
| } // namespace base
|
|
|
|
|