michael@0: // Copyright (c) 2011 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef BASE_THREADING_THREAD_CHECKER_IMPL_H_ michael@0: #define BASE_THREADING_THREAD_CHECKER_IMPL_H_ michael@0: michael@0: #include "base/base_export.h" michael@0: #include "base/synchronization/lock.h" michael@0: #include "base/threading/platform_thread.h" michael@0: michael@0: namespace base { michael@0: michael@0: // Real implementation of ThreadChecker, for use in debug mode, or michael@0: // for temporary use in release mode (e.g. to CHECK on a threading issue michael@0: // seen only in the wild). michael@0: // michael@0: // Note: You should almost always use the ThreadChecker class to get the michael@0: // right version for your build configuration. michael@0: class BASE_EXPORT ThreadCheckerImpl { michael@0: public: michael@0: ThreadCheckerImpl(); michael@0: ~ThreadCheckerImpl(); michael@0: michael@0: bool CalledOnValidThread() const; michael@0: michael@0: // Changes the thread that is checked for in CalledOnValidThread. This may michael@0: // be useful when an object may be created on one thread and then used michael@0: // exclusively on another thread. michael@0: void DetachFromThread(); michael@0: michael@0: private: michael@0: void EnsureThreadIdAssigned() const; michael@0: michael@0: mutable base::Lock lock_; michael@0: // This is mutable so that CalledOnValidThread can set it. michael@0: // It's guarded by |lock_|. michael@0: mutable PlatformThreadId valid_thread_id_; michael@0: }; michael@0: michael@0: } // namespace base michael@0: michael@0: #endif // BASE_THREADING_THREAD_CHECKER_IMPL_H_