| Index: base/threading/thread_checker.h
|
| diff --git a/base/threading/thread_checker.h b/base/threading/thread_checker.h
|
| index 712b5b56f03efeb429dd9231bfc8807a99c0dc32..33b6764e966b269bfceadeba4ad94b8ce4d0bc32 100644
|
| --- a/base/threading/thread_checker.h
|
| +++ b/base/threading/thread_checker.h
|
| @@ -7,22 +7,34 @@
|
| #pragma once
|
|
|
| #ifndef NDEBUG
|
| -#include "base/synchronization/lock.h"
|
| -#include "base/threading/platform_thread.h"
|
| -#endif // NDEBUG
|
| +#include "base/threading/thread_checker_impl.h"
|
| +#endif
|
|
|
| namespace base {
|
|
|
| +// Do nothing implementation, for use in release mode.
|
| +//
|
| +// Note: You should almost always use the ThreadChecker class to get the
|
| +// right version for your build configuration.
|
| +class ThreadCheckerDoNothing {
|
| + public:
|
| + bool CalledOnValidThread() const {
|
| + return true;
|
| + }
|
| +
|
| + void DetachFromThread() {}
|
| +};
|
| +
|
| // 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,37 +46,11 @@ namespace base {
|
| // }
|
| //
|
| // In Release mode, CalledOnValidThread will always return true.
|
| -//
|
| #ifndef NDEBUG
|
| -class ThreadChecker {
|
| - public:
|
| - ThreadChecker();
|
| - ~ThreadChecker();
|
| -
|
| - bool CalledOnValidThread() const;
|
| -
|
| - // Changes the thread that is checked for in CalledOnValidThread. This may
|
| - // be useful when an object may be created on one thread and then used
|
| - // exclusively on another thread.
|
| - void DetachFromThread();
|
| -
|
| - private:
|
| - void EnsureThreadIdAssigned() const;
|
| -
|
| - mutable base::Lock lock_;
|
| - // This is mutable so that CalledOnValidThread can set it.
|
| - // It's guarded by |lock_|.
|
| - mutable PlatformThreadId valid_thread_id_;
|
| +class ThreadChecker : public ThreadCheckerImpl {
|
| };
|
| #else
|
| -// Do nothing in release mode.
|
| -class ThreadChecker {
|
| - public:
|
| - bool CalledOnValidThread() const {
|
| - return true;
|
| - }
|
| -
|
| - void DetachFromThread() {}
|
| +class ThreadChecker : public ThreadCheckerDoNothing {
|
| };
|
| #endif // NDEBUG
|
|
|
|
|