1b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat// Use of this source code is governed by a BSD-style license that can be 3b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat// found in the LICENSE file. 4b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat 5b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat#ifndef BASE_THREADING_NON_THREAD_SAFE_IMPL_H_ 6b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat#define BASE_THREADING_NON_THREAD_SAFE_IMPL_H_ 7b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat 8b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat#include "base/base_export.h" 9b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat#include "base/threading/thread_checker_impl.h" 10b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat 11b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Eratnamespace base { 12b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat 13b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat// Full implementation of NonThreadSafe, for debug mode or for occasional 14b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat// temporary use in release mode e.g. when you need to CHECK on a thread 15b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat// bug that only occurs in the wild. 16b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat// 17b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat// Note: You should almost always use the NonThreadSafe class to get 18b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat// the right version of the class for your build configuration. 19b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Eratclass BASE_EXPORT NonThreadSafeImpl { 20b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat public: 21b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat bool CalledOnValidThread() const; 22b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat 23b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat protected: 24b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat ~NonThreadSafeImpl(); 25b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat 26b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat // Changes the thread that is checked for in CalledOnValidThread. The next 27b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat // call to CalledOnValidThread will attach this class to a new thread. It is 28b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat // up to the NonThreadSafe derived class to decide to expose this or not. 29b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat // This may be useful when an object may be created on one thread and then 30b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat // used exclusively on another thread. 31b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat void DetachFromThread(); 32b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat 33b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat private: 34b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat ThreadCheckerImpl thread_checker_; 35b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat}; 36b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat 37b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat} // namespace base 38b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat 39b8cf94937c52feb53b55c39e3f82094d27de464cDaniel Erat#endif // BASE_THREADING_NON_THREAD_SAFE_IMPL_H_ 40